Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!gorodish!guy From: guy@gorodish.Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: exit(-1), 0 is sometimes magic Message-ID: <39799@sun.uucp> Date: 23 Jan 88 05:01:42 GMT References: <502@cresswell.quintus.UUCP> <6935@brl-smoke.ARPA> <1179@wjvax.UUCP> <562@cresswell.quintus.UUCP> Sender: news@sun.uucp Lines: 24 Keywords: exit, zero, shells > Beware, by the way. Due to byte sex problems, even in UNIX, the > result of system() may be shifted left by 8 (it is on a SUN). Nope. This has nothing to do with byte sex problems, and is true on all non-broken UNIX implementations (even those with a byte size other than 8 bits). On UNIX systems, "system()" calls "wait()" to wait for the shell that runs the command to terminate; the value that "wait()" stuffs into the "int" pointed to by its first argument is what "system()" returns. The exit status of the shell is always shifted left by 8 in the value returned by "wait()"; the low order 8 bits are used if the shell stops or is terminated by a signal. (Ignore the fact that in BSD systems "wait" is nominally declared as returning a "union wait". The BSD *kernel* code still returns an "int", in the same way that all other UNIX implementations do. The "union wait" was, I presume, an attempt to make it easier to pull the exit status apart. Unfortunately, since the order of bit fields in a structure is implementation-dependent, that structure is not portable! Note that the Sun version of that structure has "#ifdef"s giving one definition for little-endian VAXes and another for big-endian Sun-3s and Sun-4s.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com