Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Handling KILL signal in a perl script (http://www.velocityreviews.com/forums/t899162-handling-kill-signal-in-a-perl-script.html)

Swarup Baran 07-25-2006 12:26 PM

Handling KILL signal in a perl script
 
Hello All,

Here is what the scenario is...

I have a perl script which runs for hours reading data and processing
it.

What i need to handle is if this perl process gets a kill process
either because of a manual kill or machine reboot etc. I should be
able to trap it, clean up if any resources and then EXIT.

Is it possible to do so? An urgent reply would be appreciated.

Thanks & Regards,
Swarup


David Squire 07-25-2006 12:36 PM

Re: Handling KILL signal in a perl script
 
Swarup Baran wrote:
> Hello All,
>
> Here is what the scenario is...
>
> I have a perl script which runs for hours reading data and processing
> it.
>
> What i need to handle is if this perl process gets a kill process
> either because of a manual kill or machine reboot etc. I should be
> able to trap it, clean up if any resources and then EXIT.
>
> Is it possible to do so?


Yes. See perldoc perlvar, and look for $SIG.

> An urgent reply would be appreciated.


That is no way to talk to a newsgroup. When you are paying us you can
tell is it's urgent.


DS


anno4000@radom.zrz.tu-berlin.de 07-25-2006 12:40 PM

Re: Handling KILL signal in a perl script
 
Swarup Baran <swarup.baran@gmail.com> wrote in comp.lang.perl.misc:
> Hello All,
>
> Here is what the scenario is...
>
> I have a perl script which runs for hours reading data and processing
> it.
>
> What i need to handle is if this perl process gets a kill process
> either because of a manual kill or machine reboot etc. I should be
> able to trap it, clean up if any resources and then EXIT.


Look up %SIG in perlvar.

> Is it possible to do so? An urgent reply would be appreciated.


"Urgent" and "Usenet" don't go together.

Anno

Paul Lalli 07-25-2006 01:48 PM

Re: Handling KILL signal in a perl script
 
Swarup Baran wrote:
> What i need to handle is if this perl process gets a kill process
> either because of a manual kill or machine reboot etc. I should be
> able to trap it, clean up if any resources and then EXIT.


My understanding is that SIGKILL is very specifically *not* trappable.
Otherwise, it would be possible to write a program that simply cannot
be stopped (short of rebooting the machine). To wit:

$ perl -e'$SIG{$_} = sub { print "Caught SIG$_[0]\n" } for keys %SIG; 1
while 1' &
[1] 18338
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE
9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSR1
17) SIGUSR2 18) SIGCHLD 19) SIGPWR 20) SIGWINCH
21) SIGURG 22) SIGIO 23) SIGSTOP 24) SIGTSTP
25) SIGCONT 26) SIGTTIN 27) SIGTTOU 28) SIGVTALRM
29) SIGPROF 30) SIGXCPU 31) SIGXFSZ 32) SIGWAITING
33) SIGLWP 34) SIGFREEZE 35) SIGTHAW 36) SIGCANCEL
37) SIGLOST
$ kill -1 18338
Caught SIGHUP
$ kill -2 18338
Caught SIGINT
$ kill -3 18338
Caught SIGQUIT
$ kill -4 18338
Caught SIGILL
$ kill -9 18338
[1]+ Killed perl -e'$SIG{$_} = sub { print "Caught SIG$_[0]\n"
} for keys %SIG; 1 while 1'
$ ps -u plalli
PID TTY TIME CMD
17896 pts/4 0:00 bash
$

> Is it possible to do so? An urgent reply would be appreciated.


That's just plain rude. If you need urgency, you hire a consultant.
If you want free help, you accept it whenever someone feels like giving
it to you.

Paul Lalli


Dr.Ruud 07-25-2006 01:54 PM

Re: Handling KILL signal in a perl script
 
anno4000@radom.zrz.tu-berlin.de schreef:

> "Urgent" and "Usenet" don't go together.


But they can!

Isn't there a Perl-sponsor-site where people can Pal-Pay there
donations?
http://donate.perl-foundation.org/

Poster should mention the URL of the confirmed payment, to speed up the
answers.
;)

--
Affijn, Ruud

"Gewoon is een tijger."



A. Sinan Unur 07-25-2006 02:11 PM

Re: Handling KILL signal in a perl script
 
"Paul Lalli" <mritty@gmail.com> wrote in news:1153835306.539633.129170
@h48g2000cwc.googlegroups.com:

> Swarup Baran wrote:
>> What i need to handle is if this perl process gets a kill process
>> either because of a manual kill or machine reboot etc. I should be
>> able to trap it, clean up if any resources and then EXIT.

>
> My understanding is that SIGKILL is very specifically *not* trappable.
> Otherwise, it would be possible to write a program that simply cannot
> be stopped (short of rebooting the machine).


IIRC, On the *nix machines I have run, issuing the reboot command from the
prompt, results in the OS sending a SIGHUP, followed by a KILL. Presumably,
the SIGHUP is to allow processes to clean up.

I must admit, I am rather ignorant in these areas.

Sinan

A. Sinan Unur 07-25-2006 02:13 PM

Re: Handling KILL signal in a perl script
 
"Dr.Ruud" <rvtol+news@isolution.nl> wrote in news:ea5evk.1h8.1
@news.isolution.nl:

> anno4000@radom.zrz.tu-berlin.de schreef:
>
>> "Urgent" and "Usenet" don't go together.

>
> But they can!
>
> Isn't there a Perl-sponsor-site where people can Pal-Pay there
> donations?
> http://donate.perl-foundation.org/
>
> Poster should mention the URL of the confirmed payment, to speed up the
> answers.
> ;)
>


As an economist, I very much like that idea.

There would have to be a disclaimer of warranty specifically crafted for
this purpose, to reflect the fact that the donation really is just a
donation, not a fee-for-service. The donation would provide us with a
motivation to help the donor as quickly as we can if we know the answer.

Sinan

anno4000@radom.zrz.tu-berlin.de 07-25-2006 03:45 PM

Re: Handling KILL signal in a perl script
 
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> "Paul Lalli" <mritty@gmail.com> wrote in news:1153835306.539633.129170
> @h48g2000cwc.googlegroups.com:
>
> > Swarup Baran wrote:
> >> What i need to handle is if this perl process gets a kill process
> >> either because of a manual kill or machine reboot etc. I should be
> >> able to trap it, clean up if any resources and then EXIT.

> >
> > My understanding is that SIGKILL is very specifically *not* trappable.
> > Otherwise, it would be possible to write a program that simply cannot
> > be stopped (short of rebooting the machine).

>
> IIRC, On the *nix machines I have run, issuing the reboot command from the
> prompt, results in the OS sending a SIGHUP, followed by a KILL. Presumably,
> the SIGHUP is to allow processes to clean up.


SIGHUP isn't universal, I think, but the procedure is: First send
a catchable signal and wait a bit, then SIGKILL all processes that
haven't got the hint.

Anno

xhoster@gmail.com 07-25-2006 04:14 PM

Re: Handling KILL signal in a perl script
 
xx087+news@ncf.ca wrote:
> At 2006-07-25 09:48AM, Paul Lalli <mritty@gmail.com> wrote:
> > Swarup Baran wrote:
> > > What i need to handle is if this perl process gets a kill process
> > > either because of a manual kill or machine reboot etc. I should be
> > > able to trap it, clean up if any resources and then EXIT.

> >
> > My understanding is that SIGKILL is very specifically *not* trappable.

>
> Indeed. My Camel book says: "Some signals can be neither trapped nor
> ignored, such as the KILL and STOP signals."


I don't think the OP was considering SIGKILL specifically, but rather using
the generic term for any signal generated by (Perl or unix) kill commands,
which by default in fact or not SIGKILL. He would probably want to trap
HUP, INT, and QUIT, and TERM.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

Peter J. Holzer 07-25-2006 04:43 PM

Re: Handling KILL signal in a perl script
 
On Tue, 25 Jul 2006 14:11:09 +0000, A. Sinan Unur wrote:
> "Paul Lalli" <mritty@gmail.com> wrote in news:1153835306.539633.129170
> @h48g2000cwc.googlegroups.com:
>> Swarup Baran wrote:
>>> What i need to handle is if this perl process gets a kill process
>>> either because of a manual kill or machine reboot etc. I should be
>>> able to trap it, clean up if any resources and then EXIT.

>>
>> My understanding is that SIGKILL is very specifically *not* trappable.
>> Otherwise, it would be possible to write a program that simply cannot
>> be stopped (short of rebooting the machine).

>
> IIRC, On the *nix machines I have run, issuing the reboot command from the
> prompt, results in the OS sending a SIGHUP, followed by a KILL. Presumably,
> the SIGHUP is to allow processes to clean up.


I think you mean SIGTERM. SIGHUP is usually used to tell daemons to
reload their configuration.

hp


--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd



All times are GMT. The time now is 07:59 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.