LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: alex.zud

请教:fork的用法

[复制链接]
发表于 2005-4-27 15:38:02 | 显示全部楼层
fork叉子的意思本来进程是一直线在进行:-------
这个时候fork被调用,进程一分为二:
padding_____
----------|_____

就好像一把叉子。分裂成的两个进程的地址空间完全一样,可以理解为原有进程的所有东西都在内存中被复制了一份(虽然操作系统实现上并不一定是这样)。两个进程唯一不同的是看到的fork函数的返回值,原有进程看到的是新进程的进程号,新进程看到的是0。
fork函数可以说是unix系统最优美的一个调用了,windows下的CreateProcess真是看到了都晕。
回复 支持 反对

使用道具 举报

发表于 2005-4-30 19:18:45 | 显示全部楼层
看外文书,这些方面的资料多数是英文的比较权威。
回复 支持 反对

使用道具 举报

发表于 2005-4-30 23:18:20 | 显示全部楼层
Post by Tetris
两个进程唯一不同的是看到的fork函数的返回值

兄弟此言差矣
看apue的192页(清华影印版)
回复 支持 反对

使用道具 举报

发表于 2005-4-30 23:22:26 | 显示全部楼层
Post by nait
兄弟此言差矣
看apue的192页(清华影印版)


有问题么?刚好书不在身边你解释一下好了。
回复 支持 反对

使用道具 举报

发表于 2005-4-30 23:34:21 | 显示全部楼层
Post by nait
兄弟此言差矣
看apue的192页(清华影印版)


应该还有其它一些不同的,呵呵。比如进程的一些属性,前台后台什么的。
回复 支持 反对

使用道具 举报

发表于 2005-5-1 00:03:37 | 显示全部楼层
不过进程的属性信息并不是在进程地址空间里的吧?进程空间里除了fork的返回值还有别的不同么?
回复 支持 反对

使用道具 举报

发表于 2005-5-1 09:03:21 | 显示全部楼层
Post by Tetris
有问题么?刚好书不在身边你解释一下好了。

  1. The differences between the parent and child are
  2. * the return value from fork
  3. * the process IDs are different
  4. * the two processes have different parent process IDs--the parent process ID of the child is the parent, the parent process ID of the parent does't change
  5. * the child's values for tms_utime, tms_stime, tms_cutime, and tms_ustime are set to 0
  6. * file locks set by the parent are not in inherited by the child
  7. * pending alarms are cleared for the child
  8. * the set of pending signals for the child is set to the empty set
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-5-1 10:38:36 | 显示全部楼层
Post by nait
  1. The differences between the parent and child are
  2. * the return value from fork
  3. * the process IDs are different
  4. * the two processes have different parent process IDs--the parent process ID of the child is the parent, the parent process ID of the parent does't change
  5. * the child's values for tms_utime, tms_stime, tms_cutime, and tms_ustime are set to 0
  6. * file locks set by the parent are not in inherited by the child
  7. * pending alarms are cleared for the child
  8. * the set of pending signals for the child is set to the empty set
复制代码


也就是说除了task_struct和fork的返回值,其它的都一样。task_struct是在内核空间里的。用户空间里的信息除了fork的返回值之外都是一样的,呵呵,又是表述上的问题。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表