wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

doublefork.c (475B)


      1 /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include <sys/wait.h>
      5 #include <unistd.h>
      6 #include "util.h"
      7 
      8 int
      9 doublefork(void) {
     10 	pid_t pid;
     11 	int status;
     12 
     13 	switch(pid=fork()) {
     14 	case -1:
     15 		fatal("Can't fork(): %r");
     16 	case 0:
     17 		switch(pid=fork()) {
     18 		case -1:
     19 			fatal("Can't fork(): %r");
     20 		case 0:
     21 			return 0;
     22 		default:
     23 			exit(0);
     24 		}
     25 	default:
     26 		waitpid(pid, &status, 0);
     27 		return pid;
     28 	}
     29 	/* NOTREACHED */
     30 }