Before looking at the signal, there is not much attention to the comparison of different signals. When I see it again today, I suddenly feel very similar to some of the signals, and even very easy to confuse. Let's take a moment to summarize this weekend.
first, close the process signal
The common 4 off process signal is sigkill,sigint,sigterm,sigquit.
- SIGKILL, which is used to close processes, cannot be captured or ignored. The scenario is that the administrator kills some resource-hogging processes or orphan processes that are out of control.
- Sigint,interrupt (interrupt) process, this is can be captured and ignored. You can use CTRL + C to send a signal directly to the parent process and to the child process, so that all the processes of the program can be shut down.
- The Sigterm,terminate (terminate) process, which can also be captured and ignored. Compared with SIGINT, there is no corresponding keyboard control command. If you want to close all the processes, you can only send all the processes one by one.
- The Sigquit,quit (exit) process, which can also be captured and ignored. You can use ctrl+\ to send a signal directly to the parent process and to the child process. If it is not captured, he will produce a core file.
The best thing about keyboard shortcuts is that they are sent to all processes.
At the bottom we use the program to verify.
first set of shutdown process signaling program validation
First, the code.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void process (int signo) {
printf ("signo:%d,pid:%d\n", Signo,getpid ());
}
void Cleanup () {
printf ("cleanup,pid:%d\n", Getpid ());
}
int main ()
{
pid_t pid;
Atexit (cleanup);
Signal (SIGINT, process);
Signal (SIGTERM, process);
Signal (sigquit, process);
if (PID = fork ()) = = 0)
{
printf ("Child pid:%d\n", Getpid ());
while (1) {
Sleep (1);
}
}else{
printf ("Parent pid:%d\n", Getpid ());
while (1) {
Sleep (1);
}
}
return 0;
}
Sigkill is relatively simple, we will no longer verify. First verify the SIGINT.
When you can see the input CTRL + C, the parent-child process receives the relevant signal. But when I entered Kill-2 742, only the parent process was received and not passed to the child process.
Below we verify that sigquit produces core.
Perhaps some of the machine defaults are not generated, we need to enter several commands.
#设置core文件大小, there is no limit
Ulimit-c Unlimited
#core后面跟着pid
sudo sysctl kernel.core_uses_pid=1
#core文件存放路径, put it under the current folder
sudo sysctl kernal.core_pattern=core
second, stop the signal
Compared to the previous group, this set of signals is much simpler.
SIGSTOP, program hangs, no corresponding shortcut keys, cannot be captured and ignored.
SIGTSTP, program hangs, shortcut keys CTRL + Z, can be captured as well as ignored.
If you hang up, how do you get them to start again? Simply put, we can enter jobs and then look at their index values. Then FG starts them up.
We can also send them sigcont signals to get them up and up. But this time, they can only run in the background.
At this point, you can see that their state has changed from T to S, from the stop to the running state.
Reference Link: http://www.linuxidc.com/Linux/2015-05/117695.htm
Linux Two-group signal comparison (shutdown and stop process signals)