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

Maarten Litmaath maart at nat.vu.nl
Fri Mar 8 07:20:33 AEST 1991


In article <shj.668195000 at dkuugin>,
	shj at login.dkuug.dk (Stig Jacobsen) writes:
>[...]
>Yeah! It was something like this that I wanted, where I get no
>ugly messages splattering over the parents screen and where I get
>an error return from the spawn call and not via some signal. [...]

One thing I forgot to mention: don't forget to wait() for the child,
_even_ when the spawn() has failed!

If your UNIX variant has wait4(2), waitfor(2) or waitpid(2), you can
let spawn() itself take care of it in case the execvp() has failed.

Otherwise things must be handled by a routine that takes care of all
children, if any.

The interface might be changed to:

	int	spawn(argv, pidp)
	char	**argv
	int	*pidp;

..and spawn() would return the PID in `*pidp'.

Do _not_ use the simple wait(2) system call in spawn(), as that may
reap other children as well...  The other forms of wait() weren't
invented for nothing.



More information about the Comp.unix.programmer mailing list