Comparison of two groups of signals in Linux and two groups of signals in Linux
Blog gradually migrated to, independent blog, original address http://www.woniubi.cn/two_groups_signal_difference/
When looking at the signal, I did not pay too much attention to the comparison of different signals. when I saw it again today, I suddenly felt that some signals were very similar and even very confusing. I will take the time to summarize this weekend.
The first group disables the process signal.
In common 4, the signal for disabling a process is SIGKILL, SIGINT, SIGTERM, and SIGQUIT.
Signal |
Can be captured? |
Keyboard shortcuts |
Whether to generate core files |
SIGKILL
|
No |
|
|
SIGINT
|
Yes |
Ctrl + c |
|
SIGTERM
|
Yes
|
|
|
SIGQUIT
|
Yes
|
Ctrl + \ |
Yes |
The biggest benefit of keyboard shortcuts is to send them to all processes.
At the bottom, we use a program for verification.
The first group disables process signal Program Verification
Run the code first.
#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 and we will not verify it. Verify the SIGINT first.
When ctrl + c is input, the Parent and Child processes receive signals. However, when I enter kill-2 742, only the parent process receives the message and will not pass it to the child process.
Next we will verify that SIGQUIT generates core.
Some machines are not generated by default. We need to enter several commands.
# Set the core file size. Here there is no limit to ulimit-c unlimited # The core is followed by pidsudo sysctl kernel. core_uses_pid = 1 # path for storing the core file, put sudo sysctl kernal in the current folder. core_pattern = core
Second group stop signal
This set of signal comparison is much simpler than the previous set.
If they are suspended, how can they start again. Simply put, we can enter jobs and check their index values. Then fg starts them.
We can also send SIGCONT signals to them to start them up. However, they can only run in the background at this time.
At this time, we can see that their status has changed from T to S, from stop to run.