前不久遇到很匪夷所思的bug, 在fork的子进程中做了简单的打印输出,然后退回到主进程,就20+几行的code,结果就出现了panic。
查来查去,原来是exit()捣乱,如果在子进程中使用exit(),它会使stdio buffers被flush两次,并且一些temp的文件被同时删除。所以如果你在子进程,请用_exit()退出。
More information please refer to:
http://www.unixguide.net/unix/programming/1.1.3.shtml
and
http://stackoverflow.com/questions/2329640/how-to-exit-a-child-process-exit-vs-exit