Home > Archive > PERL Miscellaneous > October 2004 > how to kill a process initiated by system()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to kill a process initiated by system()
|
|
| Howard 2004-10-27, 3:57 pm |
| Hi All,
I ran into a scenario that I initiate from system(), however, the
process doesn't exit and hang over there. I am just wondering if there
is a way to kill the process after half hour run no matter it is
healthy or not.
Regards,
| |
| Thomas Kratz 2004-10-27, 3:57 pm |
| Howard wrote:
> Hi All,
>
> I ran into a scenario that I initiate from system(), however, the
> process doesn't exit and hang over there. I am just wondering if there
> is a way to kill the process after half hour run no matter it is
> healthy or not.
>
> Regards,
perldoc -f alarm
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
| |
| Anno Siegel 2004-10-27, 3:57 pm |
| Howard <hao.luan@gmail.com> wrote in comp.lang.perl.misc:
> Hi All,
>
> I ran into a scenario that I initiate from system(), however, the
> process doesn't exit and hang over there. I am just wondering if there
> is a way to kill the process after half hour run no matter it is
> healthy or not.
That will be hard to do, because system() only returns after the external
process has ended. You could set an alarm timer and kill the process
from the signal handler if you knew the pid, but you don't.
You'll be much better off creating the child process yourself, probably
using explicit fork. The parent process knows the pid and can kill
the child process when it runs too long.
Anno
| |
| Anno Siegel 2004-10-27, 3:57 pm |
| Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote in comp.lang.perl.misc:
> Howard wrote:
>
>
> perldoc -f alarm
Fine if you know what pid to kill, but with system() you don't.
Anno
| |
| Thomas Kratz 2004-10-27, 3:57 pm |
| Anno Siegel wrote:
> Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> wrote in comp.lang.perl.misc:
>
>
>
> Fine if you know what pid to kill, but with system() you don't.
>
> Anno
You're right. Foggy memory, I really should test before posting.
It's time to go home now :-)
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
|
|
|
|
|