[Twisted-Python] [andrea at cpushare.com: Re: error after launching cpushare client]

Tommi Virtanen tv at twistedmatrix.com
Thu Aug 4 01:47:39 EDT 2005

Andrea Arcangeli wrote:
> Ok but then do you have an idea where the 139 comes from? I'd like to
> understand what's going on, to me that 139 number comes out of the blue.

139 == 128 + 11.

One way to set up the numbering is that exit codes are 0..127, signals
etc. have hight bit set.

Naturally, all real access should go through the macros WIFEXITED etc,
but that's how the number ranges are classically set up.

>>Actual .status values are unportable, thus transferring them raw over
>>the network is not a good idea.
> status should be the same that waitpid returns, from the docs:
> "return a tuple containing its pid and exit status indication: a 16-bit
> number, whose low byte is the signal number that killed the process, and
> whose high byte is the exit status (if the signal number is zero); the
> high bit of the low byte is set if a core file was produced.
> Availability: Unix."

I think you are reading about os.wait and twisted is using
os.waitpid. Otherwise, the document is lying to you. The status _may_ be
laid out like that on _some_ platform, but unless python does some
readjustment, the only portable way to access it is WIFEXITED and

cat >crash.c <<EOF
int main(void) {
  /* comment out the next line if you want a normal exit */
  *(char*)0 = 42;
  return 34;
cat >run.py <<EOF
import os

pid = os.fork()
if pid:
    # parent
    pid, status = os.waitpid(pid, 0)
    print pid, status
    if os.WIFEXITED(status):
        print 'exited', os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        print 'signaled', os.WTERMSIG(status)
        print 'coredump', os.WCOREDUMP(status)
    elif os.WIFSTOPPED(status):
        print 'stopped', os.WSTOPSIG(status)
    elif os.WIFCONTINUED(status):
        print 'continued'
        print 'unknown'
    # child
    os.execv('./a.out', ['a.out'])
    raise RuntimeError, "exec failed"
chmod a+x run.py
gcc -Wall crash.c

> Now I will ask to use exitCode but still I'd like to understand how
> status is connected with exitCode.

exitCode and signal are decoded from status.

> BTW, I was using exitCode already, but I thought it would be set only if
> a signal wasn't delivered. Infact I wrote code like this:

Exactly. If a process exits due to a signal, there is no exit code in
the sense of calling _exit(2).

More information about the Twisted-Python mailing list