473,769 Members | 6,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2311
In article <93************ **************@ posting.google. com>,
ra****@cps.cmic h.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.washingt on.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 ZeroDivisonErro r in python:

$ python -c "2/0"
Traceback (most recent call last):
File "<string>", line 1, in ?
ZeroDivisionErr or: 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
3696
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 application), I fork off a process to run independently and do some heavy-duty multi- threaded I/O churning. The process is launched with os.spawnvp(). The user may, at any time, elect to terminate this process before it reaches its end. I...
1
4134
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 soon as it's received. The problem comes when many children exit at the same time and their father seems to miss some of them. This happens quite often, but not always.
34
15033
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 and many more... Thank You Regards
11
2974
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
3143
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: 2004-06-30 08:30:19 LOG: checkpoint process (PID 28423) was terminated by signal 11 2004-06-30 08:30:19 LOG: terminating any other active server processes 2004-06-30 08:30:19 WARNING: terminating connection because of crash of another...
13
17720
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() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n");
3
1833
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 S.c, which have a named pipe between them and send each other signals. R process starts first, it opens a named pipe and waits for S to connect. S connects to the pipe, writes something to it and sends the signal to R indicating that R can read....
5
6647
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 another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
5
2522
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
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.