Date: Tue, 28 Apr 1998 13:51:04 +0800 From: Greg Lehey <grog@lemis.com> To: geoffr@globalserve.net, questions@FreeBSD.ORG Subject: Re: Return Codes Multiplied by 256 Message-ID: <19980428135104.34171@papillon.lemis.com> In-Reply-To: <35438F8E.63B2CCBD@globalserve.net>; from Geoffrey Robinson on Sun, Apr 26, 1998 at 03:48:30PM -0400 References: <35438F8E.63B2CCBD@globalserve.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 26 April 1998 at 15:48:30 -0400, Geoffrey Robinson wrote: > I'm writing a front end CGI to interface with another program I've written. > The front end program uses popen() to create a pipe to the first program > and gets the return code from pclose(). The program that is piped to uses > exit() to return an error code other than 0 if a problem occurs. At first I > thought I was getting garbage values returned but then I discovered that > all the returned where multiplied by 256. > > If I divide the value returned by 256 I get one of the return codes I > specified in my program but I'm afraid something may be wrong if I'm > getting it back as a multiple of 256. Can somebody verify that this is > supposed to happen, or not. This is a feature, not a bug. The value that you return via exit (n) or 'return n' from the main() function is only part of the information that wait(2) returns to you. The man page does its best to be misleading, but what you really get is a 16 bit structure with the following components: 8 bits return code (the one that the programs returns) 1 bit core dumped indication (set if the program core dumped) 7 bits signal which terminated program (0 if no signal) Greg To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980428135104.34171>