errormsg in childprozess

Doug Gwyn gwyn at smoke.brl.mil
Mon Mar 25 18:09:43 AEST 1991


In article <91.082.19:00:19 at mute.ruhr.de> frank at mute.ruhr.de (Frank Huemme) writes:
>ret=fork();
>if (ret==0)			/* in child */
>	{
>	execlp(.........
>	exit();
>	}
>What`s the best way for the child to tell the father-process if something
>was going wrong with execlp ( and fork() was ok )??

This is a UNIX-specific question, better asked in comp.unix.questions.
However, the answer is that there are several possible solutions.  Note
first of all that "exit()" is incorrect; exit() requires an argument,
and that is one method of reporting failure to the parent, which if it
wait()s on the child will be able to use the exit status to determine
whether of not the child had a problem.  (Actually you should use _exit()
in this context, to avoid unwanted flushing of the forked copy of the
stdio buffers.)  If the parent is not waiting on the child, you could
send a signal from the child branch to the parent branch before the
child branch terminates, and have the parent use a signal handler to set
a flag that you can test at appropriate places.



More information about the Comp.lang.c mailing list