Massyn has asked for the wisdom of the Perl Monks concerning the following question:
#!/fellow/monks.pl On both AIX and Mandrake Linux, I'm experiencing a problem where programs spawned from within a perl script doesn't get killed when the parent dies. Yeah, children should live longer than their parents, but not in a perl script, I would think. Here's my code (and I've tried many different ways of opening tail)..
So touch testlog.txt, run the script, and start a 2nd session. Do a ps -ef and you'll see the process running, along with the spawned tail. Kill the parent, and the child becomes almost orphaned, using the inittab as it's parent. How can I kill the child when the parent dies, or at least spawn the child that it's dependant on the parent's survival??#!/usr/bin/perl open (HTML, "-|") or exec("tail","-f","testlog.txt"); print while <HTML>;
[gmassyn@apt01m04 gmassyn]$ ps -ef |grep test gmassyn 7755 7712 0 21:57 pts/0 00:00:00 /usr/bin/perl ./testb. +pl gmassyn 7756 7755 0 21:57 pts/0 00:00:00 tail -f testlog.txt gmassyn 7758 7712 0 21:57 pts/0 00:00:00 grep test [gmassyn@apt01m04 gmassyn]$ kill -9 7755 [gmassyn@apt01m04 gmassyn]$ [1]+ Killed ./testb.pl [gmassyn@apt01m04 gmassyn]$ ps -ef |grep test gmassyn 7756 1 0 21:57 pts/0 00:00:00 tail -f testlog.txt gmassyn 7764 7712 0 21:57 pts/0 00:00:00 grep test [gmassyn@apt01m04 gmassyn]$
Thanks!
|\/| _. _ _ ._
www. | |(_|_>_>\/| | .net
/
The more I learn the more I realise I don't know.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automatically killing a child
by BrowserUk (Patriarch) on May 19, 2006 at 04:02 UTC | |
|
Re: Automatically killing a child
by Zaxo (Archbishop) on May 19, 2006 at 04:32 UTC | |
|
Re: Automatically killing a child
by mojotoad (Monsignor) on May 19, 2006 at 08:16 UTC | |
by nobull (Friar) on May 20, 2006 at 14:00 UTC | |
|
Re: Automatically killing a child
by ioannis (Abbot) on May 19, 2006 at 03:10 UTC | |
|
Re: Automatically killing a child
by sgifford (Prior) on May 19, 2006 at 03:44 UTC | |
|
Re: Automatically killing a child
by bbfu (Curate) on May 19, 2006 at 04:26 UTC | |
|
Re: Automatically killing a child
by ikegami (Patriarch) on May 19, 2006 at 02:20 UTC | |
by Fletch (Bishop) on May 19, 2006 at 15:27 UTC | |
|
Re: Automatically killing a child
by roboticus (Chancellor) on May 19, 2006 at 13:05 UTC | |
by Massyn (Hermit) on May 24, 2006 at 21:45 UTC |