Reputation: 41
I'm new to the OS and I met some problems when learning Linux signal handling.
In Linux, if a signal arrives during a syscall such as pause(), the program will switch to kernel mode and runs the signal handler. Then depending on the handler function, the program will do whatever the function tells it to do. What if the syscall is important and can't/shouldn't be interrupted? (Or does there exist such sys call that can't be interrupted by a signal?)
Also, what would happen if a signal arrives when the kernel is processing another signal which arrived earlier? Will the new signal be captured later?
Thank you very much!
Upvotes: 0
Views: 451
Reputation: 18410
If you do not want a syscall to be interrupted by a signal, you can mask all (catchable) signals with sigprocmask(2)
:
sigset_t fullset;
sigfillset(&fullset);
sigprocmask(SiG_SETMASK, fullset, NULL);
SIGKILL
and SIGSTOP
can not be blocked.
If a signal arrived while it was blocked the handler will be executed when the corresponding signal is removed from the mask again.
Upvotes: 0
Reputation: 179779
You're mistaken. A signal handler does not run in kernel mode, but in user mode. It would be a major escalation of privileges bug is a normal application could get kernel mode access.
You're also wondering about a syscall being interrupted. This isn't a concern, for the same reason: the signal affects only the application, not the kernel handling the syscall.
Upvotes: 1