Shell script runs two functions as child processes (via &).
Both of them went to sleep (via sleep command).
Is it possible to wake them?
I have their pids.
P.s.
I don't want to run sleep with & and wait
Shell script runs two functions as child processes (via &).
Both of them went to sleep (via sleep command).
Is it possible to wake them?
I have their pids.
P.s.
I don't want to run sleep with & and wait
A rather barbaric way to do this would be to kill the sleep
process (not the whole subshell in which your script/function runs). Consider the following shell script:
#!/bin/bash
sleep 20
echo "Done!"
or, with a function:
#!/bin/bash
function gotosleep()
{
sleep 20
echo "Done!"
}
gotosleep &
sleep 60 # Not really necessary, keeps the script in foreground.
Then, find the sleep
process:
$ ps -ef | grep sleep
you PID PGID ... sleep 20
And kill it:
$ kill PID
You script will then output (at least in bash
):
./script.sh: line 2: PID Terminated sleep 20
Done!
Since you don't want to wait
properly, you'll have to do with Bash's little message. If you change your mind, have a look at this question:
sleep 20 &
if wait $! 2>/dev/null; then
# Keep working
continue
else
echo "Done!"
return # from function
fi
sleep
process runs in the same "shell" the function does (if you use a function). The only time I used &
was to send the function to background, which is exactly what you did.
– John WH Smith
May 08 '16 at 14:44
sleep
doesn't mean they are suspended forever. What are you actually trying to do? – l0b0 May 08 '16 at 14:35