I have a server application which I want to protect from being stopped by any signal which I can ignore. Is there a way to ignore all possible signals at once, without setting them one by one?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Yes:
This does not exactly ignore the signals, but blocks them; which in practice is the same effect.
I guess there's no need to mention that
SIGKILL
andSIGSTOP
cannot be blocked nor ignored in any way.For more detailed semantics, like mask inheritance rules and the like, check the man page
Blocking signals is NOT the same as ignoring them.
When you block signals as suggested by C2H5OH, it gets added to a pending signal queue and will be delivered to the process as soon as you unblock it.
Unblocking can be done using
To answer your question on how to ignore signals, it has to be handled by a Signal Handler which is a user-defined function which executes whenever a signal is delivered to the process
then register this function by using
If you want to ignore all signals
This code will take all the signals delivered to the process and ignore them instead of blocking them.
NOTE: According to man pages , it is not the recommended way, instead sigaction is suggested. Do check out
man sigaction
Solutions based on
sigprocmask()
andpthread_sigmask()
have not worked for me. Here's what I found to work: