Confusing documentation about system(3) in 4.3BSD?

David H. Brierley dave at galaxia.zone1.com
Sat Feb 27 13:37:30 AEST 1988


In article <3161 at phri.UUCP> roy at phri.UUCP (Roy Smith) writes:
>
>	printf ("%d\n", system ("exit 1"));
>you get:
>	256
>
>	Clearly what is going on is that system() is returning the exit
>status as described in wait(2), i.e. with the argument to exit() shifted up
>one byte, and the low byte containing the termination status.  But, as I
>read the man pages, the above fragment should have printed 0, 1, 2, and 3.

This subject has come up several times recently so I thought I'd put my two
cents worth in.  As you have guessed, system() is indeed returning the exit
status as defined by wait().  The initial reason for this is obvious if you
think about it.  The way the system() routine works is to fork off another
process, wait for it to complete, and return the status.  Since system() must
use wait() to wait for the process, the reason for returning the status that
was returned by wait() is initially simply laziness.  Before anyone gets all
up in arms about my calling any of the Supreme UNIX Gods lazy, let me add that
returning the status as defined by wait() is also a good thing.  It's entirely
possible that whoever wrote system() returned the wait() status on purpose
and if not they probably looked back and said "this is a good thing, leave
it alone" when they realized what they had done.  The exit status has other
information in it other than just the value that was passed to exit() and
that information could be of use to someones program.  For example, I might
want to take one action if the program exited with a status of 1 and a
different action if the program died with a segmentation fault.

I think whats really needed is for someone to rewrite the manual page for
system() to clearly indicate that the exit status is defined by wait().
-- 
David H. Brierley
Home: dave at galaxia.zone1.com   ...!rayssd!galaxia!dave
Work: dhb at rayssd.ray.com       {sun,decuac,cbosgd,gatech,necntc,ukma}!rayssd!dhb



More information about the Comp.unix.wizards mailing list