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