lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, May 17, 2013 at 9:06 AM, Thijs Schreijer
<thijs@thijsschreijer.nl> wrote:
> The results (see below) are what I expected for Windows. But on Ubuntu, I
> can’t explain it.
>
> The exitcodes are supposed to be between 0 and 255. So the os.exit(-5) and
> os.exit(400) are out of range, but the valid test; os.exit(25) also gives me
> a return value in os.execute() of 6400.

6400 == 25 * 256.

The status returned by C functions such as system() and wait() encodes
the actual exit status, the signal that terminated the program, and
whether the program dumped core. POSIX specifies macros to extract
these bits of information from the returned status value.

On my system, the exit status is encoded in the high byte (read with
(status & 0xff00) >> 8), the signal in the low byte (read with status
& 0x7f), and the core-dumped flag in status & 0x80. Also, status &
0xff == 0x7f indicates the child is stopped, and status == 0xffff
indicates that the child continued from being stopped.

But it doesn't look like this is standardized beyond just "these
macros should be provided" and that status == 0 means a normal exit(0)
or the equivalent. So other systems could encode this information in
different ways.