Detecting exec(2) failing after performing fork(2)?

Tom DeNapoli denap at alta.sw.stratus.com
Tue Mar 5 00:12:54 AEST 1991


>>>>> On 1 Mar 91 20:59:44 GMT, rosenqui at crc.skl.dnd.ca (Eric Rosenquist) said:

[original post deleted] 

rosenqui> It's too late once the fork() has completed.  What you need to do is
rosenqui> have the child exit in a particular way that your SIGCLD handler looks
rosenqui> for if the exec() fails.  In your code snippet the child keeps
rosenqui> executing!

rosenqui> 	if (fork() == 0) {
rosenqui> 		execlp(path, NULL);
rosenqui> 		/* if you get here, the exec() failed */
rosenqui> 		exit(SOME_STATUS_CODE);
rosenqui> 		/* or */
rosenqui> 		abort() or kill(...) etc.
rosenqui> 	}

along the same lines... prior to exiting the child could use a
write back to the parent through a pipe with more details of the
failure. 

rosenqui> Eric @ SKL
rosenqui> -------------
rosenqui> Eric.Rosenquist at crc.skl.dnd.ca
rosenqui> Software Kinetics Limited
rosenqui> 65 Iber Road, Stittsville, Ontario
rosenqui> Canada - K2S 1E7  Phone (613) 831-0888
--
  Tom DeNapoli              | Stratus Computer, Inc.
  denap at alta.sw.stratus.com | 55 Fairbanks Blvd M23EN3
  uunet!lectroid!alta!denap | Marlboro, MA 01752



More information about the Comp.unix.programmer mailing list