By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,927 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,927 IT Pros & Developers. It's quick & easy.

Delivered signal info in exit status of a process?

P: n/a
Here is a piece code (according to blurb on os.wait, the lower
order 7 bits of exit status of process should contain the signal
number of signal that terminated the process..) and signal number
should be 8 (SIGFPE), similar logic in C-code produces expected
result.

Any pointers?

-ishwar
----
import os

cpid = os.fork()
if cpid == 0:
2 / 0 # divide by zero
else if cpid > 0:
ps, st = os.wait()
print 'child got signal: %d, exit status: %d' %(st&0177, st>>8)

prints::

child got signal: 0, exit status 1
---
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <93**************************@posting.google.com >,
ra****@cps.cmich.edu (Ishwar Rattan) wrote:
Here is a piece code (according to blurb on os.wait, the lower
order 7 bits of exit status of process should contain the signal
number of signal that terminated the process..) and signal number
should be 8 (SIGFPE), similar logic in C-code produces expected
result.

Any pointers?

-ishwar
----
import os

cpid = os.fork()
if cpid == 0:
2 / 0 # divide by zero
else if cpid > 0:
ps, st = os.wait()
print 'child got signal: %d, exit status: %d' %(st&0177, st>>8)

prints::

child got signal: 0, exit status 1
---


One branch of this question leads into Python's
arithmetic and whether SIGFPE plays any role there.
I sure don't know (I would have thought the FP stood
for floating point, but anyway I see the effect isn't
very different if I actually use floating point values.)
Maybe someone who would know will read this thread despite
the subject line.

But even if a SIGFPE is in fact delivered to the interpeter
as a rule on a divide by zero, at any rate the end result
is a Python exception. If you execute the instructions
directly, for example at the interpreter prompt, you'll
get a traceback and notification, or whatever result the
effective exception handler at the time gives you. You
could expect an error (non-zero status) exit, from the
default exception handler for a script, but not a termination
signal.

And I hope the documentation mentioned that you might use
os.WTERMSIG() instead of the computation above - not that
it's necessarily different, but it will be more reliable
where layout of the signal value can change (it isn't the
same on all UNIX-like platforms.)

Donn Cave, do**@u.washington.edu
Jul 18 '05 #2

P: n/a
Ishwar Rattan wrote:
Here is a piece code (according to blurb on os.wait, the lower
order 7 bits of exit status of process should contain the signal
number of signal that terminated the process..) and signal number
should be 8 (SIGFPE), similar logic in C-code produces expected
result.


But that's not what happens when you throw a ZeroDivisonError in python:

$ python -c "2/0"
Traceback (most recent call last):
File "<string>", line 1, in ?
ZeroDivisionError: integer division or modulo by zero

$ echo $? # this is the exit status in bash
1

If there is a SIGFPE, Python is trapping it and turning it into an
exception. And it exits with status 1 due to an uncaught exception.
--
Michael Hoffman
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.