Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!rayssd!galaxia!dave From: dave@galaxia.zone1.com (David H. Brierley) Newsgroups: comp.unix.wizards Subject: Re: Confusing documentation about system(3) in 4.3BSD? Message-ID: <428@galaxia.zone1.com> Date: 27 Feb 88 03:37:30 GMT References: <3161@phri.UUCP> Reply-To: dave@galaxia.zone1.com (David H. Brierley) Organization: Dave's Very Own Personal System Lines: 34 Keywords: exit status In article <3161@phri.UUCP> roy@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@galaxia.zone1.com ...!rayssd!galaxia!dave Work: dhb@rayssd.ray.com {sun,decuac,cbosgd,gatech,necntc,ukma}!rayssd!dhb