Comparison of two sets of Linux signals

Source: Internet
Author: User

Blog gradually migrated to, independent blog, the original address http://www.woniubi.cn/two_groups_signal_difference/

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 set of shutdown process signals

The common 4 off process signal is sigkill,sigint,sigterm,sigquit.

    1. 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.
    2. 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.
    3. 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.
    4. 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.
Signal Whether it can be captured keyboard shortcut keys Whether to produce a core file
SIG KILL
Whether

SI GINT
Is CTRL + C
SIG Term
Is


SIG QUIT
Is
CTRL + Is

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文件大小, here is the unrestricted ulimit-c unlimited #core后面跟着pidsudo sysctl kernel.core_uses_pid=1#core file storage path, placed under the current folder sudo sysctl Kernal.core_pattern=core
Second set of stop signals

Compared to the previous group, this set of signals is much simpler.

    1. SIGSTOP, program hangs, no corresponding shortcut keys, cannot be captured and ignored.
    2. 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.

Comparison of two sets of Linux signals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.