문제

I was wondering if it was possible to manually wake a perl script that has gone to sleep. Basically I set my script to sleep for say an hour after performing something, and 10 minutes later I realize I want it to run again.

The platform I'm running on is linux, with a tcsh shell.

Again, Thanks for any help

도움이 되었습니까?

해결책

On many systems, system calls like sleep can be interrupted with signals. On such an interruption, sleep will return the number of seconds that it actually slept for and set $!. Of course you have to use a signal that will allow your script to continue. If you haven't set any specific signal handler, a combination of SIGSTOP and SIGCONT will do the trick, too.

Example:

$ perl -e 'print "slept for ", sleep 1000, " seconds.\n";' &
[2] 6220
$ kill -STOP 6220
$ kill -CONT 6220
slept for 8 seconds[2]+  Stopped     perl -e ...

Another example (trivial SIGUSR1 handler):

$ perl -e '$SIG{USR1}=sub{}; print "slept for ", sleep 1000, "s.\n"' &
[1] 2419
$ kill -USR1 2419
slept for 4s
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top