C fork dealing with global variable

前端 未结 5 1181
谎友^
谎友^ 2021-01-05 01:37

I\'m not understanding the output of this program:

#include 
#include 
#include 

int i = 0;

int main()
{
           


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 01:50

    Fork will make a copy of the process. An independent copy of the process. So, if a global variable contains 3 at the time you fork, each copy of the process gets their very own 3. And if they modify, their modifications are completely independent.

提交回复
热议问题