training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

ex-8.6.c (478B)


      1 /*
      2  * Advanced Programming in the UNIX(r) Environment
      3  *
      4  * Exercise 8.6
      5 */
      6 
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <sys/types.h>
     10 #include <unistd.h>
     11 
     12 int
     13 main(void)
     14 {
     15    pid_t pid;
     16 
     17    if( (pid = fork()) == -1 ) {
     18       perror("fork");
     19       return EXIT_FAILURE;
     20    }
     21    else if( pid ) {
     22 #if !defined(__linux__)
     23       sleep(1); /* Wait a bit to make a zombie */
     24 #endif
     25       system("ps");
     26    }
     27 
     28    return EXIT_SUCCESS; /* Make C compiler happy! */
     29 } /* eof main() */
     30