Proc::Background killing parent process when child dies

P

Paul Clements

Hi,

I have a perl script which spawns processes by use of Proc::Background
and this works fine.

One of the child processes accesses a database and if that database is
down I want as well as the child process to die, I want the parent
process to exit.

Any clues on how to do this would be very much appreciated

Regards

Paul
 
T

thumb_42

Paul Clements said:
Hi,

I have a perl script which spawns processes by use of Proc::Background
and this works fine.

One of the child processes accesses a database and if that database is
down I want as well as the child process to die, I want the parent
process to exit.

Any clues on how to do this would be very much appreciated

Regards

Paul

I've never used Proc::Background, but in a fork() environment, you can store
the parent process ID to a variable (prior to fork()) and then from the child
send a signal to the parent. kill($PARENT_PID,<whatever_signal>); If you've
got multiple child processes, you'll probably want the parent to tell the
other child procs to exit as well. (just use an event handler in
the %SIG array to do this.)

Jamie
 
B

Ben Morrow

I have a perl script which spawns processes by use of Proc::Background
and this works fine.

One of the child processes accesses a database and if that database is
down I want as well as the child process to die, I want the parent
process to exit.

Any clues on how to do this would be very much appreciated

If you're on a Unix system, catch SIGCHLD and check it against a list
of spawned processes.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top