I am trying to understand the following piece of code
#include
#include
#include
int main()
{
pid_t pid ;
uns
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
- modifies any data other than a variable of type pid_t used to store the return value from vfork()
- returns from the function in which vfork() was called
- 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.