vfork() system call

◇◆丶佛笑我妖孽 提交于 2019-12-05 09:06:56

You should read the man page for vfork very carefully:

The vfork() function has the same effect as fork(2), except that the behavior is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(), or returns from the function in which vfork() was called, or calls any other function before successfully calling _exit(2) or one of the exec(3) family of functions.

(above is from the POSIX part of the man page, so applies (potentially) to other environments than Linux).

You're calling printf and returning from the child, so the behavior of your program is undefined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!