home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_07 / 9n07110a < prev    next >
Text File  |  1991-05-28  |  1KB  |  64 lines

  1. /*  This program is called as follows 
  2.  
  3. a.out exit_value program_name arguments...
  4.  
  5. exit_value is the value which the program will exit with
  6.  
  7. program_name is the name of the child process to exec, with
  8. its arguments
  9. */ 
  10.  
  11. #include <stdio.h>
  12. #include <signal.h>
  13.  
  14. static int RET_VALUE;        
  15. #define TRUE 1
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char **argv;
  20. {
  21. RET_VALUE = atoi(argv[1]);
  22. argc -= 2;
  23. argv += 2;
  24. process(argc,argv);
  25. printf("Parent exiting with %d\n", RET_VALUE);
  26. exit(RET_VALUE);
  27. }
  28.  
  29. process(argc,argv)
  30. int argc;
  31. char **argv;
  32. {
  33. int pid;
  34. int status;
  35. int ret; 
  36. signal(SIGINT,SIG_IGN); /* Ignore interrupt key */
  37. pid = fork();
  38. if (pid == -1)
  39.   {
  40.   perror("all_true");
  41.   exit(126);
  42.   }
  43.  
  44. if (pid > 0 )
  45.  {
  46.  printf("In parent, waiting for child\n");
  47.  /* In parent */ 
  48.  /* Wait for child */ 
  49.  ret = wait(&status);è         printf("Exit status from child is %x\n", status);
  50.  if (ret == -1)
  51.      perror("all_true");
  52.  return;
  53.  }
  54.  
  55. /* In child */
  56. printf("Executing %s in child\n", argv[0]);
  57. signal(SIGINT, SIG_DFL);
  58. execvp(*argv, argv);
  59. perror("all_true");
  60. }
  61.  
  62.  
  63.  
  64.