From owner-freebsd-questions Wed Apr 29 02:38:00 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA08115 for freebsd-questions-outgoing; Wed, 29 Apr 1998 02:38:00 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from freebie.lemis.com (freebie.lemis.com [139.130.136.133]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA08059 for ; Wed, 29 Apr 1998 02:37:48 -0700 (PDT) (envelope-from grog@lemis.com) Received: from papillon.lemis.com ([192.122.138.250]) by freebie.lemis.com (8.8.8/8.8.7) with ESMTP id TAA19987; Wed, 29 Apr 1998 19:06:30 +0930 (CST) (envelope-from grog@lemis.com) Received: (grog@localhost) by papillon.lemis.com (8.8.8/8.6.12) id NAA00715; Tue, 28 Apr 1998 13:51:06 +0800 (SGT) Message-ID: <19980428135104.34171@papillon.lemis.com> Date: Tue, 28 Apr 1998 13:51:04 +0800 From: Greg Lehey To: geoffr@globalserve.net, questions@FreeBSD.ORG Subject: Re: Return Codes Multiplied by 256 References: <35438F8E.63B2CCBD@globalserve.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89i In-Reply-To: <35438F8E.63B2CCBD@globalserve.net>; from Geoffrey Robinson on Sun, Apr 26, 1998 at 03:48:30PM -0400 WWW-Home-Page: http://www.lemis.com/~grog Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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