#include <stdio.h> #include <stdlib.h> #include <SYS / types.h> #include <signal.h> #include <unistd.h>
void Handler ( int Arg) { the printf ( " the receive the SIGCHLD \ n- " ); } int main ( int argc, const char * the argv []) { signal (the SIGCHLD, Handler); // registration signal callback function will be called when a signal occurs Handler pid_t PID; PID = the fork (); iF ( PID < 0 ) { perror ( "Fail the fork " ); Exit ( . 1 ); } the else IF (PID == 0 ) // child process { the while ( . 1 ) { the printf ( " Child \ n- " ); SLEEP ( . 1 ); } } the else // parent { sLEEP ( . 1 ); // sleep one second the kill (pid, the SIGKILL); // kill pid signal transmission process, kill transmission signal, process number to specify the other processes the printf ( " Child killed \ n- " ); printf ( " Father \ the n- " ); the wait (NULL); // wait for recycling the child process raise (SIGKILL); // kill their signal, sends a signal to their function raise } return 0 ; }
test: