The theory says that, if wait is not called parent wont be getting information about terminated child and child becomes zombie. But when we create a process, zombies are not created even if we are not calling wait. My question is whether the wait is called automatically?
In many languages, calling a sub process will call wait()
for you. For example, in ruby or perl, you often shell out like this:
#!/usr/bin/ruby
system("ls /tmp")
`ls /tmp`
This is doing a bunch of magic for you, including calling wait()
. In fact, Ruby must wait for the process to exit anyway to collect the output before the program can continue.
You can easily create zombies like this:
#!/usr/bin/ruby
if fork
sleep 1000 # Parent ignoring the child
else
exec "ls /tmp" # short-lived child
end
When we manually fork/exec, there is no magic calling wait()
for us, and a zombie will be created. But when the parent exits, the zombie child will get re-parented to init
, which will always call wait()
to clean up zombies.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.