Re: signal processing INT or TERM



On Wed, Oct 29, 2008 at 13:50, icarus <rsarpi@xxxxxxxxx> wrote:
perl 5.8.2
OS: AIX fully POSIX compliant

my script moves files from one dir to another.
When I want my script to stop, should I pass it along the signal INT
or TERM?

INT just interrupts the script. It finishes whatever it's processing
and then it's done.

TERM on the other hand, just sends a TERMination signal, waits a few
seconds, then KILLs the program. TERM is more common I guess when
starting/stopping unix shell scripts in the init dir.

My fear is that if I pass the TERM signal, maybe the system will chop
off the files that are being moved on the fly. The "few seconds" are
unpredictable in value at least on my system. So the system might say
'it's been too long, let's kill it."

Any thoughts? Is there a "perlish" way to do it?

I'd send a custom signal (say, USR1). When the script receives that
signal, it sets a flag indicating it should perform a clean exit.
Totally untested:

----------
my $done = 0;

sub sigusr {
$done = 1;
}

$SIG{USR1} = \&sigusr;

while(!$done)
{
# Do something
}
# Clean up and exit
----------

It won't work if "do something" is perpetually blocked on a read or
somesuch, but if you wake up periodically to go through the loop,
you'll be fine.

--
Mark Wagner
.



Relevant Pages

  • Re: killall like linuxs
    ... You could always use this Perl script which I wrote earlier. ... It kills all the processes you specify on the command line ... and all their descendents as well. ... It also prints out the pids, users, and command lines of the ...
    (comp.unix.solaris)
  • Re: Bash script problem
    ... >> How can I change my script so that it kills all its child processes, ... after the exec, script.sh isn't there anymore. ... but the killall command won't work either... ...
    (Debian-User)
  • Re: CPU Hog script....
    ... I am trying to write a script or if someone has already done it even ... certain process lets' call it "build_cache" and when it see's the CPU ... it kills it. ... echo "Following runaway build_cache processes were found and killed\n ...
    (comp.unix.shell)
  • CPU Hog script....
    ... I am trying to write a script or if someone has already done it even ... it kills it. ... # reset the temp file, ... echo "Following runaway build_cache processes were found and killed\n ...
    (comp.unix.shell)
  • signal processing INT or TERM
    ... OS: AIX fully POSIX compliant ... When I want my script to stop, should I pass it along the signal INT ... seconds, then KILLs the program. ...
    (perl.beginners)