Linux application Development-signal programming
one signal for interprocess communication
The signal is defined under/usr/include/asm/signal.h.
The common signals are:
Sigkill Kill Process
Sigstop pausing a process
Notifies the parent process when a SIGCHLD child process stops or ends
Two-related functions
Send Signal
Function name Kill
function prototype int Kill (pid_t pid, int sig)
function function sends a signal to any process and process group
Owning header file
#include <sys/types.h>
#include <signal.h>
return value
Successful return 0
Failed return-1
Parameter description
pid > 0 PID parameters point to the process of receiving the signal
PID = 0 signal is sent to each process in the process group
PID = 1 signal is sent to every process that has permission to send a signal, in addition to the INIT process
PID <-1 signal sent to process group PID-pid Process
SIG indicates the signal to be sent
Processing signal
Function name Signal
Function prototype
typedef void (*sighandler_t) (int)
sighandler_t signal (int signal, sighandler_t handler)
function function set the signal processing mode
Owning header file
#include <signal.h>
return value
function pointers for successful return processing
Failed to return Sig_err
Parameter description
Signal the signal to be processed
Handler:
Sig_ign: Ignore this signal, do not process
SIG_DFL: Handing over to kernel processing
User-defined function handling
Linux application development-signal programming