vfork() atexit assertion failed

前端 未结 1 1468
我寻月下人不归
我寻月下人不归 2021-01-25 05:53

I am trying to understand the following piece of code

#include
#include
#include

int main()
{
pid_t pid ;
uns         


        
相关标签:
1条回答
  • 2021-01-25 06:45

    It's unclear what you are trying to do or understand, but here is a slightly edited quote from the manual:

    The vfork() function has the same effect as fork(2), except that the behavior is undefined if the process created by vfork() either

    1. modifies any data other than a variable of type pid_t used to store the return value from vfork()
    2. returns from the function in which vfork() was called
    3. calls any other function before successfully calling _exit(2) or one of the exec(3) family of functions

    You are doing both 1: i++ and 3 printf("%d\n", i). Whatever you expect, it won't work.

    As a side note, vfork isn't bad. Just tricky, dangerous, almost useless and removed from SUSv4.

    0 讨论(0)
提交回复
热议问题