473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Delivered signal info in exit status of a process?

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
2 2275
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Elf M. Sternberg | last post by:
I'm having a devil of a time with signal handling under BSD 4.4 with Python and I was hoping that this might ring a bell with someone. Using the Webware Application Server (a multi-threaded Python...
1
by: Jorge | last post by:
All, I've got a process that creates some children and want to be alerted when they die. To do this, the SIGCHLD signal is registered in the process using sigaction to jump to a subprogram as...
34
by: Kishor | last post by:
Hi Friends Click here : www.c4swimmers.esmartguy.com to Test Your C Programming Strengths. You can find Tricky Questions on C, Interview type queries on C, Infrequently Answered Questions in C...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
13
by: Christopher Cashell | last post by:
Yesterday, while attempting to access a database, I received errors saying that the database was innaccessible. After investigating a little, I found the following in the PostgreSQL log files: ...
13
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() {...
3
by: norm4h8 | last post by:
Hi! I have a question about how to create a process in such a way that it would terminate itself if its wated for input for too long. Here is the story. I have 2 different files, say R.c and...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
5
by: Yves Dorfsman | last post by:
I did a few tests with this script: class byebye: def __del__(self): print 'Bye, bye...' x = byebye()
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.