How to block all SIGNALS in thread WITHOUT using SIGWAIT?

前端 未结 2 1854
北恋
北恋 2020-12-30 09:45

I have a main application that spawns a seperate thread to process messages off a queue. I have an issue on AIX when I hit CTRL-C as it seems to make some \"connection handl

相关标签:
2条回答
  • 2020-12-30 09:47

    Still wrong design. Do not use CTRL+C to stop an application in a controlled manner. Use a correctly designed controller app that will be accessible over CORBA, RMI, or some other method to interact with the user and control the background app.

    Have fun guys...

    0 讨论(0)
  • 2020-12-30 09:54

    With s = pthread_sigmask(SIG_BLOCK, &set, NULL); , you're not blocking anything.

    Use:

    sigfillset(&set);
    sets = pthread_sigmask(SIG_SETMASK, &set, NULL);
    

    If you want to block every signal, or explicitly add the signals you want to block to the set if you're using SIG_BLOCK.

    After you've created the threads, you need to restore the signal mask, otherwise no threads will catch any signal.

    However, looking at your previous question, it might be that the thread catching the signal doesn't handle being interrupted. That is, if you're blocked doing a syscall, and a signal arrives, that syscall gets aborted. Some operating systems defaults to automatically call the system call again, some returns an error and sets errno to EINTR, which the application must handle - and bad things might happen if that's not handled.

    Instead, install your signal handlers with sigaction() instead of signal() , and set the SA_RESTART flag, which will cause system calls to automatically restart in case it got aborted by a signal.

    0 讨论(0)
提交回复
热议问题