About fork system call and global variables

前端 未结 5 1553
遥遥无期
遥遥无期 2021-01-15 04:57

I have this program in C++ that forks two new processes:

#include 
#include 
#include 
#include 

        
5条回答
  •  余生分开走
    2021-01-15 05:29

    This is called "virtual address". Each process has its own address space, and each address means something different, depending on the process. fork() creates a copy, instead of sharing data (technically, they may get shared copy-on-write, but this is has the same effect as upfront copying would). IOW, the variable "shared" is not shared between processes.

提交回复
热议问题