LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 895|回复: 3

谁能帮忙一下解释一下fork()函数是干什么用的?

[复制链接]
发表于 2003-3-18 12:01:21 | 显示全部楼层 |阅读模式
为什么函数fork()会return一个int值,好像是跟程序进程有关,但是不不太清楚是什么关系,请专家帮忙,谢谢。
发表于 2003-3-18 12:18:48 | 显示全部楼层
fork()产生子进程....
发表于 2003-3-19 11:04:25 | 显示全部楼层
Try "man fork", and read it.
Basically, fork() creates a child process.
In original process, fork() returns the ID of child process.
In child process, fork() returns 0.
发表于 2003-3-21 21:49:00 | 显示全部楼层

特别耗资源的东西

产生一个除id外和父进程一模一样的新进程,具体用法是这样的:

pid_t p;
if((p = fork()) > 0)
{
  /* 父进程,p为子进程id */
}
else if (p == 0)
{
  /* 子进程 */
}
else
{
  /* 出错 */
}

如果只是要多线程,可以用pthread库。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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