473,403 Members | 2,270 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,403 software developers and data experts.

Orphaned child processes

I'm using the Python processing module. I've just run into a problem
though. Actually, it's a more general problem that isn't specific to
this module, but to the handling of Unix (Linux processes) in general.
Suppose for instance that for some reason or another, after forking
several child processes, the main process terminates or gets killed
(or segfaults or whatever) and the child processes are orphaned. Is
there any way to automatically arrange things so that they auto-
terminate or, in other words, is there a way to make the child
processes terminate when the parent terminates?

Thank you.
Apr 7 '08 #1
2 2058
ro*********@gmail.com wrote:
I'm using the Python processing module. I've just run into a problem
though. Actually, it's a more general problem that isn't specific to
this module, but to the handling of Unix (Linux processes) in general.
Suppose for instance that for some reason or another, after forking
several child processes, the main process terminates or gets killed
(or segfaults or whatever) and the child processes are orphaned. Is
there any way to automatically arrange things so that they auto-
terminate or, in other words, is there a way to make the child
processes terminate when the parent terminates?

Thank you.
Put a thread in the child which reads stdin, and make stdin
connect to a pipe from the parent. When the parent terminates,
the child will get a SIGPIPE error and raise an exception.

John Nagle
Apr 7 '08 #2
In article <47***********************@news.sonic.net>,
John Nagle <na***@animats.comwrote:
ro*********@gmail.com wrote:
I'm using the Python processing module. I've just run into a problem
though. Actually, it's a more general problem that isn't specific to
this module, but to the handling of Unix (Linux processes) in general.
Suppose for instance that for some reason or another, after forking
several child processes, the main process terminates or gets killed
(or segfaults or whatever) and the child processes are orphaned. Is
there any way to automatically arrange things so that they auto-
terminate or, in other words, is there a way to make the child
processes terminate when the parent terminates?

Thank you.

Put a thread in the child which reads stdin, and make stdin
connect to a pipe from the parent. When the parent terminates,
the child will get a SIGPIPE error and raise an exception.

John Nagle
That could work, but not precisely in that manner. You get
SIGPIPE when you write to a closed pipe. When you read from one,
you get end of file, i.e., a normal return with 0 bytes.

When you test it, make sure to try a configuration with more
than one child process. Since the parent holds the write end
of the pipe, subsequently forked child processes could easily
inherit it, and they'll hold it open and spoil the effect.

Donn Cave, do**@u.washington.edu
Apr 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
6
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with...
2
by: Rech | last post by:
Hi, I need a little help here managing child processes in Python. I'm not so skilled in system programming so I hope you can give me some good suggestions. I have a very CPU and memory...
1
by: Jason Godden | last post by:
Hi All, I've written a few C functions in the version 1 format as well as some SPI based backend bits and I'm curious as to how PG treats these items when used within plpgsql. The set of...
0
by: tiger | last post by:
Hi I was working on a project for school, that deals with processes and windows.....here is a sample of the instruction: You are to implement a game of Nim. Your implementation should consist...
0
by: tiger | last post by:
Hi I was working on a project for school, that deals with processes and windows.....here is a sample of the instruction: You are to implement a game of Nim. Your implementation should consist...
0
by: Wizou | last post by:
1. Create a TcpListener 2. Start a child Process 3. Kill the parent process => You can't bind to the port until you close the child process Variant : 3. Terminate normally the parent process...
2
by: Fred Heida | last post by:
Hi, Question on Vista Run As Administrator. If i have exe which creates a child process, using the Process class, and this exe is Run As Asministror, is there a way to have the child process...
22
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.