c*********t 发帖数: 2921 | 1 标 题: 问问跟Linux Kernel 有关的问题
发信站: BBS 未名空间站 (Tue Apr 15 22:49:16 2008)
本人对Linux kernel是菜鸟,有问题请大家指正。
Q1. 关于system call fork()
当parent process用fork()去创建一个child process时,child process得到一个独立
于parent process的地址空间,child process 得到了和parent process完全一样的内
存内容(所有的变量都继承了过来)。从此,child process 和parent process可以独立
的操作自己的变量,互不影响,这对一般的变量来说,很容易理解,毕竟他们在不同的
地址。我的疑问是,如果在fork()前, parent process 有一个file descriptor(对应
于一个打开的文件),在child process被创建后,如果child process close那个file
descriptor,在parent process看来,它的那个file descripto | t****t 发帖数: 6806 | 2 Q1. This is not about kernel programming; this is "system call". Common Unix
system calls are mostly portable, by conforming to various standards (e.g.
POSIX).
For your specific question: Parent and child process has their separate file
descriptor, but their "open file description", which is system-wide, are
shared. You may think each pair of descriptors are cloned via dup(2). That
means, they have the same file offset, the same I/O attributes. However,
they may be "closed" separately, as I unde
【在 c*********t 的大作中提到】 : 标 题: 问问跟Linux Kernel 有关的问题 : 发信站: BBS 未名空间站 (Tue Apr 15 22:49:16 2008) : 本人对Linux kernel是菜鸟,有问题请大家指正。 : Q1. 关于system call fork() : 当parent process用fork()去创建一个child process时,child process得到一个独立 : 于parent process的地址空间,child process 得到了和parent process完全一样的内 : 存内容(所有的变量都继承了过来)。从此,child process 和parent process可以独立 : 的操作自己的变量,互不影响,这对一般的变量来说,很容易理解,毕竟他们在不同的 : 地址。我的疑问是,如果在fork()前, parent process 有一个file descriptor(对应 : 于一个打开的文件),在child process被创建后,如果child process close那个file
|
|