總的來說,子程序将複制父親程序的資料段,BSS段,代碼段,堆空間,棧空間和檔案描述符。而對于檔案技術符關聯核心檔案表項(即STRUCT FILE結構),則是采取了共享的方式。
下面代碼說明。
I值分離,但FD共享。
結果:
[root@localhost ~]# gcc -o fork_descriptor fork_descriptor.c
[root@localhost ~]# ./fork_descriptor
in child i = 2
in parent i = 1
[root@localhost ~]# cat test.txt
helloworldIN