Next | Unix Command Internals | 29 |
Related to signal handling is the alarm clock
Every process has an alarm clock
When the alarm clock goes off, the kernel sends the process an ALRM signal
The alarm clock is preserved across exec, but not copied on fork
We can use it to make a useful utility, stopafter:
#!/usr/bin/perl my ($limit, $command, @args) = @ARGV; $SIG{ALARM} = 'IGNORE'; alarm $limit; exec $command, @args; die "Couldn't run '$command': $!";
To use:
stopafter 30 command arg arg arg...
stopafter just sets up an alarm clock and then execs the program you asked for
30 seconds later, the alarm clock goes off
The ALRM signal is delivered
The process dies
(Unless the command cancelled the alarm clock or caught or ignored the ALRM signal)
Next | Copyright © 2003 M. J. Dominus |