Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!ucivax!orion.oac.uci.edu!ucsd!pacbell.com!ames!haven!cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!cathedral!kannan From: kannan@cathedral.cerc.wvu.wvnet.edu (R. Kannan) Newsgroups: comp.unix.questions Subject: error handling when errno == ECHILD ... Keywords: fork execlp wait -- system calls ... Message-ID: <1040@babcock.cerc.wvu.wvnet.edu> Date: 2 Dec 90 00:12:20 GMT Sender: news@cerc.wvu.wvnet.edu Lines: 87 -- here is the code .... switch ( ( pid = fork () ) ) { case -1 : close ( fdin ) ; close ( fdout ) ; close ( fderr ) ; return ( AMS_OVRLD ) ; case 0 : execlp("sh","sh","-c",command, (char *) 0 ) ; exit ( 127 ) ; default: istat = signal ( SIGINT, SIG_IGN ) ; qstat = signal ( SIGQUIT, SIG_IGN ) ; while ( (w=wait(&status)) != pid && w != -1 ) ; signal ( SIGINT, istat ) ; signal ( SIGQUIT, qstat ) ; } /* CLOSE THE OUTPUT FILES */ close ( fdin) ; close (fdout) ; close (fderr) ; if ( w == -1 ) return (AMS_SVRERR); return ( 0 ) ; -- END of code .... ERROR SCENARIO Running small applications like "ps", wait returns -1 and errno is set to ECHILD. FROM THE MANUAL ERRORS wait(), wait3(), or wait4() will fail and return immediately if one or more of the following are true: ECHILD The calling process has no existing unwaited-for child processes. EFAULT statusp or rusage points to an illegal address. EINTR The function was interrupted by a signal. The value of the location pointed to by sta- tusp is undefined. question#1: Is it safe to assume that ECHILD is an harmless error and that it is not necessary to propagate the system error any further? by modifying the above code to if ( w == -1 && errno != ECHILD ) return (AMS_SVRERR); because: ECHILD only implies that the child process does no longer exist. ECHILD does not imply that there CHILD quit abnormally. That is indicated in status. request#2:(not a question) Could someone share with us piece of code that analyzes the return value in "status" for all possible error conditions. Thanks --kannan