I know if a subprocess does not get reaped properly, it will become a zombie and you can see it by ps command.

Also the "wait [pid]" command will wait for subshell running on the background until it finishes and reap it.

I have a script like this:

sleep 5 &

tail -f /dev/null

My question is, I don't use wait after sleep 5 & and the parent shell will never terminate because of tail, then why the sleep 5 & will not become a zombie? I see it disappear after finishing in ps, not sure who reaps it?


2 Answers 2


This is one of the pitfalls with having a shell mimic the OS API. It does create confusion. In this case you are confusing wait() (linux API) with wait (bash function).

Simply enough, Bash takes care of reaping processes for you, you don't generally need to think about this. The wait bash command has no effect on reaping processes.

When your child job terminates, bash will be informed via a SIGCHLD signal. This will when that happens bash will stop whatever it was doing for a moment and reap the stopped child. It then goes back to whatever it was doing.


Your use of "&" requested the parent process to put "sleep 5" in the background, so it is the parent process that will harvest the sleep 5.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .