Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Handling KILL signal in a perl script

Reply
Thread Tools

Handling KILL signal in a perl script

 
 
Swarup Baran
Guest
Posts: n/a
 
      07-25-2006
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

 
Reply With Quote
 
 
 
 
David Squire
Guest
Posts: n/a
 
      07-25-2006
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

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-25-2006
Swarup Baran <> 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
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      07-25-2006
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 SIGFPE
9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSR1
17) SIGUSR2 1 SIGCHLD 19) SIGPWR 20) SIGWINCH
21) SIGURG 22) SIGIO 23) SIGSTOP 24) SIGTSTP
25) SIGCONT 26) SIGTTIN 27) SIGTTOU 2 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

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      07-25-2006
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."


 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-25-2006
"Paul Lalli" <> 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
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-25-2006
"Dr.Ruud" <rvtol+> wrote in news:ea5evk.1h8.1
@news.isolution.nl:

> 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
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-25-2006
A. Sinan Unur <> wrote in comp.lang.perl.misc:
> "Paul Lalli" <> 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
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      07-25-2006
xx087+ wrote:
> At 2006-07-25 09:48AM, Paul Lalli <> 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
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      07-25-2006
On Tue, 25 Jul 2006 14:11:09 +0000, A. Sinan Unur wrote:
> "Paul Lalli" <> 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?
| | | | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
KILL BABY KILL widescreen drsd2kill DVD Video 3 11-29-2004 09:36 PM
Bava's KILL BABY KILL widescreen drsd2kill DVD Video 0 11-27-2004 12:04 AM
Signal Handling/Term::ReadLine problem in Perl John C. Worsley Perl 0 01-21-2004 01:51 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57