exit() from child and status in parent wait()

CovartDL zarth at drutx.UUCP
Thu Apr 18 07:49:14 AEST 1985


I have been trying lately to use exit() in a child process and then have
the parent recieve the exit code. This is so that if the exec fails the
parent will not continue processing(or know to do error processing). The
following is part of the code I am using. I would appreciate comments and/or
suggestions. The printf statement shows rtn_code as 3 when the exec fails
and therefore the error and cleanup code is never executed.

# include <stdio.h>

int pid,wid;
unsigned int rtn_code;

if((pid = fork()) == NULL) {
   perror();
   return(0);
   }
else {
   if(pid == 0) {
      execl("cmd","cmd","arg",0);
      perror();
      exit(16);
      }
   else {
      while((wid = wait((unsigned int *)rtn_code)) != pid);
      printf("%u\n",rtn_code);
      if(rtn_code == 16) {
	 /* error processing and cleanup */
	 return(0);
	 }
      else
	 return(1);
      }
   }


Post to the net or mail to me(drutx!zarth) whichever seems appropriate.
Thanks in advance.

				Zarth Arn
				(alias Dave Coavrt)
				1-303-538-4284



More information about the Comp.lang.c mailing list