# Include <stdio. h> # Include <signal. h> # Include <string. h> # Include <sys/types. h> # Include <unistd. h> Sig_atomic_t sigusr1_count = 0; Void handler (int signal_number) { ++ Sigusr0000count; } Int main (int argc, char * argv []) { Printf ("the process ID is % d \ n", (int) getpid ()); Struct sigaction sa; Memset (& sa, 0, sizeof (sa )); Sa. sa_handler = & handler; Sigaction (SIGUSR1, & sa, NULL ); Int I = 0; While (I <100) { Sleep (1 ); I ++; } Printf ("SIGUSR was raised % d times \ n", sigusr0000count ); Return 0; } Compile the above Code as the program sigusr1 Gcc-o sigusr1 sigusr1.c Run the program [Liuchao @ localhost Signal] $./sigusr1 The process ID is 3401 On another terminal, run the ps command to obtain the sigusr1 process number. [Liuchao @ localhost ~] $ Ps- PID TTY TIME CMD 3401 pts/1 00:00:00 sigusr1 3403 pts/3 00:00:00 ps Send multiple sigusr1 signals to this process number [Liuchao @ localhost ~] $ Kill-s SIGUSR1 3401 [Liuchao @ localhost ~] $ Kill-s SIGUSR1 3401 [Liuchao @ localhost ~] $ Kill-s SIGUSR1 3401 [Liuchao @ localhost ~] $ Kill-s SIGUSR1 3401 [Liuchao @ localhost ~] $ Kill-s SIGUSR1 3401 When the process ends [Liuchao @ localhost Signal] $./sigusr1 The process ID is 3401 SIGUSR was raised 5 times |