Reputation: 983
A colleague insists that I need to call wait()
after using &
in a Bash script to spawn multiple child processes. I believe that the concern is that because the parent process is exiting before the child processes do, they'll be orphaned and left in zombie states.
I understand that fork()
requires wait()
or waitpid()
to properly delete the file descriptors it creates. However, is this really needed for Bash? Isn't this something the bash subshell each child process is running in takes care of? In my own experimentation, I have not been able to recreate a situation in which a Bash child process I've created is left in a zombie state.
Upvotes: 1
Views: 815
Reputation: 798754
Processes whose parents die are reparented to init
, which should eventually reap them when they exit. What causes zombie processes is when the parent process keeps living, but never gets around to reaping the child for some reason.
Upvotes: 2