I have a bash script that does some parallel processing in a loop. I don't want the parallel process to spike the CPU, so I use a sleep command. Here's a simplified version.
(while true;do sleep 99999;done)&
So I execute the above line from a bash prompt and get something like:
[1] 12345
Where [1]
is the job number and 12345
is the process ID (pid) of the while loop. I do a kill 12345
and get:
[1]+ Terminated ( while true; do sleep 99999; done )
It looks like the entire script was terminated. However, I do a ps aux|grep sleep
and find the sleep command is still going strong but with its own pid! I can kill the sleep
and everything seems fine. However, if I were to kill the sleep first, the while loop starts a new sleep
pid. This is such a surprise to me since the sleep is not parallel to the while loop. The loop itself is a single path of execution.
So I have two questions:
- Why did the sleep command get its own process ID?
- How do I easily kill the while loop and the sleep?
sleep
was a built-in command in bash, not some process. It makes more sense now. – Knowall