Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The signals SIGKILL and SIGSTOP cannot be caught, blocked or orignored, why?

Tags:

c

I want to know why these two signals cannot be caught, blocked, or ignored in a process? The remaining signal's action can be altered by using signal(). What is the difference between this two signal and remaining signal?

like image 361
sam Avatar asked Mar 13 '23 05:03

sam


2 Answers

If you talk about why they are blocked then the reasons are already mentioned by @Adam B..However I would like to show some internal structure. Its not that you can't really block these two signal. Only KERNEL has the ability to do it, not us.

In the implementation of signal.h, you can see there is a line like this

#define SIG_KERNEL_ONLY_MASK (rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))

This shows that these two signals are only maskable by kernel.

Another macro is wrapped around it

#define sig_kernel_only(sig) (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))

which is later used in signal.c..

one function called do_sigaction is returning EINVAL when it receives any signal having negative value or any signals which are not to be handled other than kernel.

check out this

if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
     return -EINVAL;

Obviously the system is more intricate than we can think but this is just a glimpse to show that only KERNEL is allowed to handle those signals. Not us. Other than this, there is nothing magical in the implementation of the function.

@R Sahu also talked about a very important aspect of this. The root users should also be restricted to perform certain operations which can be harmful for the system. Moreover some unresponsive or erroneous applications can be terminated when you have no choice or options to kill it..Use SIGKILL or SIGSTOP with caution..because most of the time these doesn't handle memory cleanup and other housekeeping stuffs well...use these two only when you have no other options..SIGTERM is more popular here

like image 134
Mayukh Sarkar Avatar answered Apr 06 '23 09:04

Mayukh Sarkar


These are handled by kernel. They are used to kill unresponsive tasks(applications).

When your application is itself unresponsive, there should be some way to exit the application. As your task cannot handle anything at this state, there should be a way signal is sent to the unresponsive task but is not handled by the unresponsive task itself.

SIGKILL and SIGSTOP are used for these purposes.

That is why man page says

"The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored."

These are handled by Kernel for you. There are other ample number of signals/Real time signals that you can use for your specific needs.

like image 38
Sandeep Avatar answered Apr 06 '23 10:04

Sandeep