05 February, 2010

Why fork twice?

When I were tracing the source code of lighttpd. I found out the daemonize function in server.c is quite interesting, it make itself become a daemon but it invoke fork() twice!

It seems like that there is no difference between forking once and forking twice, however, I accident found this article: http://hi.baidu.com/22000254/blog/item/9c2a01860d66713666096e38.html

The reason to fork twice is to prevent create zombie process! I never think of that before.


No comments: