First of all thank you Liao brother this friend to me last night wrote a "talk about the signal mechanism of Linux (a)", before the topic I used the word "analysis", give a person to analyze the feeling of the kernel. I know the skill is not enough, but can not be judged on the Linux kernel source code. After the road is still very long, I still step by step slowly walk, Linux kernel this mountain, I just arrived at the foot of the mountain.Well, I'll go back to the writing yesterday. If there a
child process is still running. But this time, the subprocess will be handed over to number 1th, and process 1th becomes the stepfather of these processes. The 1th process will handle the resources of these processes well, and the 1th process will automatically recycle resources when they end. So another temporary way to deal with zombie processes is to close their parent processes.
4. Signal
The general process of things mentioned above is over, but the signal in the system is indeed a very
A signal is a software interrupt, an asynchronous communication method that handles an asynchronous event. For example, we run the program in the terminal, by pressing the keyboard "CTRL + C", you can send a SIGINT interrupt signal to stop the program to run.There are 3 ways to handle the signal:1. Ignoring this signal, most signals can be handled as such. Except for Sigkill and sigstop, they must not be ignored.2. Capture the signal, the user customi
transmitted from the command line parameters */For (I = 1; I If (! Strcmp (argv [I], "-d ")){Value. sival_ptr = argv [I + 1]; // pointer to the string in the ParameterContinue;}If (! Strcmp (argv [I], "-s ")){SIGNUM = atoi (argv [I + 1]);Continue;}If (! Strcmp (argv [I], "-P ")){PID = atoi (argv [I + 1]);Continue;}}
/* Use sigqueue to send the signal SIGNUM to the PID and carry the data value */If (sigqueue (PID, SIGNUM, value) Perror ("sigqueue ");Exit (1 );}
Return 0;}
// The example uses si
also a variable. However, it is generally provided by the system to avoid the trouble of setting some variables for each operation of the software, such as setting the language or something. With the environment, these variables can be directly used. The common path, home. Command ENV, shows the environment variables of your system.
The first task is to add command line parsing so that users can enter commands and parameters in a line. The parser splits the input line into a string array and
function for a signal. For example, when you press Ctrl + C, shell will send a SIGINT signal. The default processing function of SIGINT is the exit code of the execution process, however, the following example sets the response function of SIGINT to int_handler.
#include
When executing the code above, first execute the main function, set the processing functio
the concept of a signal
Signal (signal)--the way communication between processes is a software interrupt. Once a process receives a signal, it interrupts the original program execution process to process the signal.
Several common signals:
SIGINT terminating process interrupt process (CONTROL+C)
SIGTERM terminating process software termination signal
SIGKILL Terminate process Kill process
SIGALRM Alarm Clock signalThe difference between the process e
supports non-real-time signal settings. For space purposes, we will only introduce the use of the signal function.
# Include Void (* signal (INT Sig, void (* func) (INT)
Signal () has two parameters: the first parameter is the type of the signal to be set; the second parameter is a function pointer, which stores the entry address of the signal processing function. The return value of a function is also a function pointer, and its value is the processing method before the setting. For example:
F
This article describes the Linux signal list in detail. For more information, see
Run the following command to view the list of signals supported by Linux:
~ $ Kill-l1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR213) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ26) SIGVTALRM 27) SIGP
We can use Kill-l to see all the semaphore interpretations, but we don't see the explanation for signal 0.[[Email protected]~]# kill-l 1] SIGHUP 2) SIGINT 3) sigquit 4) Sigill 5) SIGTRAP 6) SIGABRT 7) Sigbus SIGFPE 9) SIGKILL) SIGUSR1) SIGSEGV SIGUSR213) sigpipe) sigalrm) SIGTERM 17) SIGCHLD18) (Sigcont) (SIGSTOP) SIGTSTP) SIGTTIN22) Sigttou) Sigurg 25 ) (SIGXFSZ26) (SIGVTALRM) sigprof) sigwinch SIGIO30) SIGPWR
Comprehensive Case1) Create child process and parent process;2) Register SIGINT non-real-time signal and sigrtmin real-time signal, and add these two signals to the process shielding signal Group;3) Register user-defined signals;4) The sub-process sends 5 non-real-time signals and sends 5 real-time signals;5) The sub-process then sends the SIGUSR1 to unblock the sigint,sigtrmin signal.6) Observe the differe
) Perform the default operation, and Linux specifies the default action for each type of signal. Note that the default response of a process to a real-time signal is a process termination.Which of the three ways Linux responds to a signal depends on the parameters passed to the corresponding API function.Iv. Transmission of SignalsThe main functions for sending signals are: Kill (), raise (), Sigqueue (), Alarm (), Setitimer (), and Abort ().Kill (int pid, int signl) can either send a signal to
Basic conceptsThe signal is a common concept in Linux, for example, we interrupt the foreground process by pressing CTRL + C, and ending the process through the kill command is done through the signal. The following is an example of CTRL + C for a simple description of the signal processing flow:
The user presses CTRL-C and the keyboard input produces a hardware interrupt.
The process's user-space code pauses execution, and the CPU switches from the user state to the kernel-state pr
signal is a mechanism that simulates a break mechanism at the software level, and the kernel makes a process aware of a particular event. Forcing the process to execute the corresponding signal processing function. The source of the signal may come from hardware such as pressing the keyboard or hardware failure (such as CTRL + C sending SIGINT), possibly from another process (Kill,sigqueue), possibly from its own process (raise).The generation of sig
The concept of the signal
Signal (signal)--the way communication between processes is a software outage. Once a process receives a signal, it interrupts the original program execution process to process the signal.
Several common signals:
SIGINT Terminate process interrupt process (CONTROL+C)
Sigterm terminate process software termination signal
SIGKILL Terminate process Kill process
SIGALRM Alarm Clock signalthe difference between the process e
First, in order to understand the signal, start from our most familiar with the scene:
1. User input command to start a foreground process under the shell.
2. The user presses the CTRL-C, this keyboard input produces a hardware interrupt.
3. If the CPU is currently executing the code for this process, the user space code for the process is paused, and the CPU switches from user state to kernel state to process hardware interrupts.
4. The terminal driver interprets ctrl-c as a
function */...signal(SIGINT, sig_int); /* @1establish handler */ ...sig_int(){signal(SIGINT, sig_int); /* @2reestablish handler for next time */..../*process the signal ... */...}We have to use signal () again in the signal processing function ().
However, this process does not guarantee that the program is completely correct, because when a signal occurs, we start to call the sig_int function, there
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.