#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int g=100;
int main()
{
	static int x=666;
	
	pid_t pid = fork();
	if (pid==-1){
		printf("创建进程失败\r\n");
	}
	if (pid==0){
		printf("pid=%d g=%d,x=%d,g=%p,x=%p\r\n",pid,g,x,&g,&x);
		g=111;
		x=222;
		printf("我子进程 pid=%d,g=%d,x=%d,g=%p,x=%p\r\n",pid,g,x,&g,&x);
	}else{
		printf("pid=%d,g=%d,x=%d,g=%p,x=%p\r\n",pid,g,x,&g,&x);
		g=666;
		x=777;
		printf("我是父进程 pid=%d,g=%d,x=%d,g=%p,x=%p\r\n",pid,g,x,&g,&x);
		
	}
	return 0;
}
pid=4502,g=100,x=666,g=0x601044,x=0x601048
我是父进程 pid=4502,g=666,x=777,g=0x601044,x=0x601048
pid=0 g=100,x=666,g=0x601044,x=0x601048
我子进程 pid=0,g=111,x=222,g=0x601044,x=0x601048
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.