Signal Communication Programming
In the Linux system, the signal (signal) is also the oldest inter-process communication mechanism.
First, the signal type
All the signals supported by the Linux system are defined in/usr/include/asm/signal.h (display), where the common signals are:
SIGKILL: Kill Process
SIGSTOP: Pausing a process
SIGCHLD: Used to notify the parent process when a child process stops or ends
Second, function learning
2.1 Sending a signal
Name of 2.1.1 function
Kill
2.1.2 Function prototype
int Kill (pid_t pid,int SIG);
2.1.3 Function function
Send a signal to a process
2.1.4 Owning header file
<sys/types.h> <singl.h>
2.1.5 return value
Success: return 0
Failure: Return-1
2.1.6 parameter Description
Pid:if (pid>0), the PID parameter points to the process of receiving the signal
SIG: Used to indicate the signal we're sending.
2.2 Processing Signal
Name of 2.2.1 function
Signal
2.2.2 Function prototype
typedef void (*sighandler_t) (int);
sighandler_t signal (int signum,sighandler_t handler);
2.2.3 function function
Set the signal processing mode
2.2.4 Owning header file
<signal.h>
2.2.5 return value
Success: Returns a pointer to the handler function
Failed: Return Sig_err
2.2.6 parameter Description
Signum: The signal to be processed
Handler: The corresponding signal processing method, can be value (3 kinds)
Sig_ign: Ignoring this signal does not handle
SIG_DFL: Handing over to kernel processing
User-defined functions: User-defined function handling
Signal communication programming, Wang Ming Learning Learn