LINUX study note 13-inter-process communication 2 signal

Source: Internet
Author: User

A) generation: Keys, hardware exceptions, and kill functions send signals
 
B) Common signals:
 
1. SIGHUP: end signal
 
2. SIGINT: the interrupt signal ctrl + c
 
3. SIGKILL: end the process of receiving signals
 
4. SIGTERM: signal sent by the KILL command
 
5. SIGCHLD: indicates the signal that the sub-process stops or stops.
 
6. SIGSTOP: Stop Signal
 
C) signal processing:
 
1. Ignore this signal: In addition to SIGKILL, SIGSTOP
 
2. Execute the desired action:
 
3. Execute the default system action:
 
D) Sending signal:
 
1. Kill: You can send messages to yourself or someone else.
 
A) Int kill (pid_t pid, int signo );
 
B) # include <sys/types. h>
 
# Include <signal. h>
 
C) Pid:
 
1.> 0: send the signal to the process whose ID is pid.
 
1. = 0: Process sent to the same group
 
2. <0: Process sent to other groups whose IDs are equal to the absolute value of pid
 
3. =-1 send to all processes
 
D) Note: if you use the above functions in a program, you can use the kill command to send signals outside the program.
 
1. Example: Kill-s SIGINT pid
 
2. View process number: ps aux
 
2. Raise: only send messages to yourself
 
A) Int raise (int signo)
 
B) # include <sys/types. h>
 
C) # include <signal. h>
 
3. alarm: set the time to generate a SIGALARM signal. If no signal is captured, it is terminated by default.
 
A) unsigned int alarm (unsigned int seconds)
 
1. # include <unistd. h>
 
4. Pause: the process is suspended until a signal is captured, similar to wait (sub-process exited)
 
A) Int pause (void)
 
1. # include <unistd. h>
 
E) signal processing functions:
 
1. Sighandler_t signal (int signo, void (* func) (int ))
 
A) Possible Func values:
 
1. SIG_IGN: Ignore this signal
 
2. SIG_DFL: handled by default
 
3. Signal Processing Function Name: this function is used for processing. The func parameter is an integer.
 
B) # include <signal. h>
 
C) Example: signal (SIGINT, my_func );
 
1. register the signal processing function for the SIGINT signal.
 
D) Note: After registering a function, you do not need to execute the function immediately, but wait for the signal to come and then execute the function. Therefore, you must pay attention to the position of the signal registration function before capturing the signal.

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.