github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/cmd/init/init.c (about)

     1  /**
     2   * An init program that sets signal disposition for SIGCHLD (the signal that
     3   * parents usually receive when their children `exit`) to include SA_NOCLDWAIT
     4   * (so that we don't need to `wait` for children to have them not becoming
     5   * zombies when they `exit`).
     6   */
     7  
     8  #include <stdio.h>
     9  #include <unistd.h>
    10  #include <signal.h>
    11  #include <stddef.h>
    12  
    13  int
    14  main(void)
    15  {
    16  	struct sigaction act;
    17  
    18  	// retrieve the action that is currently associated with SIGCHLD
    19  	//
    20  	if (!~sigaction(SIGCHLD, NULL, &act)) {
    21  		perror("sigaction SIGCHLD");
    22  		return 1;
    23  	}
    24  
    25  	// add SA_NOCLDWAIT ("I will not bother `wait`ing for any children) to
    26  	// the set of flags associated with this signal so that we do not need
    27  	// to `wait` on a child process to have it reaped once it finishes.
    28  	//
    29  	act.sa_flags |= SA_NOCLDWAIT;
    30  
    31  	// set the action with our new flag set
    32  	// 
    33  	if (!~sigaction(SIGCHLD, &act, NULL)) {
    34  		perror("sigaction SIGCHLD SA_NOCLDWAIT");
    35  		return 1;
    36  	}
    37  
    38  	// wait for a signal to come.
    39  	//
    40  	pause();
    41  }