printf(" pid = %d, glob = %d, var = %d.\n address of gloab glob is %ld, address of local var is %ld \n",
getpid(), glob, var, &glob, &var);
exit(0);
}
测试结果:
[root@localhost c_testy]# ./tst
a write to stdout
before fork
pid = 13072, glob = 7, var = 89.
address of gloab glob is 134518672, address of local var is -1074189712
pid = 13071, glob = 6, var = 88.
address of gloab glob is 134518672, address of local var is -1074189712
[root@localhost c_testy]# uname -a
Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux
[root@localhost c_testy]#作者: 雨过白鹭洲 时间: 2009-02-04 12:25
fork就是完全复制一个进程,物理内存怎么分配不去管它,两个进程是独立的虚拟地址空间