Help: Keeping several processes in sync - one dies they all die

Help: Keeping several processes in sync - one dies they all die

Post by Samir Agarw » Thu, 13 Jun 1996 04:00:00



Hello,

This is what I would like to do:

Run some four executables (alternatively, four scripts that run one executable
each) from within a script. Now the important thing is that I need to detect
that if any one of the four processes die or killed explicitly by using kill,
then I kill the remaining processes as well and restart them all over again.

I prefer C shell but am willing to use Bourne shell.

All I can think of is using Bourne Shell to get the pid of each executable I
fork off and then periodically check to see if they are all alive, if not, kill
all the other processes and restart. A better solution (that is not quite
fully resolved in my mind) would be that each forked off script could do
a wait and if the executable it forked off died, then it could send a signal
to the parent script which can trap it and do the rest of the processing
(how?).

What happens if someone does a kill (especially -9) on the forked off script etc?

I would greatly appreciate if someone has any thoughts on this.

Thanks.

 - Samir

 
 
 

Help: Keeping several processes in sync - one dies they all die

Post by Guess Wh » Thu, 13 Jun 1996 04:00:00


: Hello,
:
: This is what I would like to do:
:
: Run some four executables (alternatively, four scripts that run one executable
: each) from within a script. Now the important thing is that I need to detect
: that if any one of the four processes die or killed explicitly by using kill,
: then I kill the remaining processes as well and restart them all over again.
:
: I prefer C shell but am willing to use Bourne shell.
:
: All I can think of is using Bourne Shell to get the pid of each executable I
: fork off and then periodically check to see if they are all alive, if not, kill
: all the other processes and restart. A better solution (that is not quite
: fully resolved in my mind) would be that each forked off script could do
: a wait and if the executable it forked off died, then it could send a signal
: to the parent script which can trap it and do the rest of the processing
: (how?).
:
: What happens if someone does a kill (especially -9) on the forked off script etc?
:
: I would greatly appreciate if someone has any thoughts on this.
:
: Thanks.
You do a fork in the first process, and save the child's pid.
 and do a fork in the child process and save it's child's pid,
 etc., etc., and you need to trap SIG_CHILD, and your sig_kill's
 (SIG_KILL, SIG_INT, etc.), and on a SIG_CHILD, kill yourself,
 but on a sig_kill, do your cleanup and kill your child.  And
 have each of the children's children do that also.

The commands to use are:

trap cleanup_child <sig_kills>
trap cleanup_exit SIG_CHILD
kill -SIG_INT $CHILDPID

You need to of course save the child's pid in CHILDPID and
 check your signals man page for the signal for SIG_CHILD, and
 the ones for the kill signals, and replace the above params
 accordingly.  cleanup_exit should rm all the /tmp files, and
 exit (number > 0), and cleanup_child should do the above, but
 before exit'ing intself call the kill for the $CHILDPID .
--
Sometimes,
 you're better off dead.
There's a gun in your hair,
 it's pointed at your head.

  -- Pet Shop Boys (West End Girls)

 
 
 

1. PC-NFS, printing, bannerpage. die.die.die

Hi, can someone tell me how I get rid of the accursed banner
page under 2.3 & PC-NFS.  Why is this bannerpage a default
in the first place?

Thanks in advance, -P.

--

Zoologiska Institutionen   | obtain a little temporary safety deserve neither
Stockholms Universitet     | liberty or safety. - Benjamin Franklin

2. Problem: select() after SIGPOLL return

3. Zombie die die die

4. root password

5. /ethan die,die,die

6. NEW Server performance monitoring tool

7. background process persist-or-die when its parent shell dies

8. Linux serving OS2

9. Son processes don't die when father die..

10. Keeping a child process alive when parent dies

11. cssd processes keep dying and respawning

12. My process keeps dying (SVR4)

13. All X-processes dies, but X keeps running??