I have a bash script that does some parallel processing in a loop. I do not want the parallel process to increase the processor, so I use the sleep command. Here is a simplified version.
(while true; do sleep 99999; done) &
So, I execute the above line from the bash prompt and get something like: [1] 12345
Where [1] is the job number, and 12345 is the process identifier (pid) of the while loop. I do a kill 12345 and get:
[1] + Terminated (while true; do
sleep 99999;
done)
It seems that the whole script has been interrupted. However, I do ps aux|grep sleep and find that the sleep command is still strong, but has its own pid! I can kill sleep , and everything seems perfect. However, if I were to first kill the sleep, the while loop starts a new sleep pid. This is such a surprise for me, because sleep is not parallel to the while loop. The loop itself is the only execution path.
I have two questions:
- Why did the sleep command get its own process id?
- How easy is it to kill a while and sleep loop?
User1 source share