home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / musbus / part04 / spawn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-16  |  710 b   |  46 lines

  1. /*
  2.  *  Process creation
  3.  *
  4.  *  $Header: spawn.c,v 3.4 87/06/22 14:32:48 kjmcdonell Beta $
  5.  */
  6.  
  7. main(argc, argv)
  8. int    argc;
  9. char    *argv[];
  10. {
  11.     int    iter;
  12.     int    slave;
  13.     int    status;
  14.  
  15.     if (argc != 2) {
  16.         printf("Usage: %s count\n", argv[0]);
  17.         exit(1);
  18.     }
  19.  
  20.     iter = atoi(argv[1]);
  21.  
  22.     while (iter-- > 0) {
  23.         if ((slave = fork()) == 0) {
  24.             /* slave .. boring */
  25. #if debug
  26.             printf("fork OK\n");
  27. #endif
  28.             exit(0);
  29.         } else if (slave < 0) {
  30.             /* woops ... */
  31.             printf("Fork failed at iteration %d\n", iter);
  32.             perror("Reason");
  33.             exit(2);
  34.         } else
  35.             wait(&status);
  36.         if (status != 0) {
  37.             printf("Bad wait status: 0x%x\n", status);
  38.             exit(2);
  39.         }
  40. #if debug
  41.         printf("Child %d done.\n", slave);
  42. #endif
  43.     }
  44.     exit(0);
  45. }
  46.