fork实现 [英] fork implementation

查看:94
本文介绍了fork实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我们知道c函数永远不会返回多个值。

那么fork()函数如何返回两个值呢?怎么样?
实现了吗?


问候

Hi All,
We know that a c function never returns more than one value.
Then how come the fork() function returns two values? How it is
implemented?

Regards

推荐答案

2006-02-08,ramu< ra ****** @ gmail.com>写道:
On 2006-02-08, ramu <ra******@gmail.com> wrote:
大家好,
我们知道c函数永远不会返回多个值。
那么fork()函数如何返回两个值呢?它是如何实现的?
Hi All,
We know that a c function never returns more than one value.
Then how come the fork() function returns two values? How it is
implemented?




magic。



magic.


ramu写道:
大家好,
我们知道ac函数永远不会返回多个值。
那么fork()函数为什么会返回两个值呢?它是如何实现的?

问候
Hi All,
We know that a c function never returns more than one value.
Then how come the fork() function returns two values? How it is
implemented?

Regards



你的问题在这里是偏离主题的,因为fork()是POSIX.1。


我会给你一个答案,但是你也应该在UNIX组中询问

的问题以获得验证:


如果您阅读fork(man fork)手册,您会看到

fork()会导致创建新进程。阅读其余的

的东西,当你到达RETURN VALUES时,它说:

成功完成后fork()返回值为0的

子进程并将子进程的进程ID

返回给父进程。因此,fork会创建项目的克隆

并将ID返回给调用进程。子进程中克隆的

fork调用返回0.两个进程在

之后继续调用,就像在两个进程上执行调用一样。

函数每次返回只返回一个值。


再次,检查相应的组,因为你可以

到得到一个更清楚的解释,它可能比我的更好



-

Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org(希望现在还不算太晚)

(......它仍然有效......)


Your question is off-topic here as fork() is POSIX.1.

I will give you an answer but you should also ask
the question in a UNIX group to get a validation:

If you read the manual for fork (man fork) you''ll see that
fork() causes the creation of a new process. Read the rest
of the stuff and when you get to RETURN VALUES it says:
Upon successful completion fork() returns a value of 0 to the
child process and returns the process ID of the child process
to the parent process. So fork creates a clone of your project
and returns with the ID to the calling process. The cloned
fork call in the child returns 0. Both processes continue after
the call like the call was executed on both processes. The
function returns only one value for every return.

Again, check the appropriate group because you may be able
to get a clearer explanation and it''s likely to be more
correct than mine.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it''s not too late)
(... and that it still works...)


-----开始PGP签名消息-----

哈希:SHA1


ramu写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ramu wrote:
大家好,
我们知道ac函数永远不会返回多个值。
那么fork()函数又如何返回两个值呢?它是如何实现的?
Hi All,
We know that a c function never returns more than one value.
Then how come the fork() function returns two values? How it is
implemented?




它不是作为C函数实现的。它被实现为一个操作系统

调用包装在C函数中。操作系统执行的原因是使fork()的返回值因进程而异。


因此,这个魔法是comp.lang.c的主题,应该在

其他一些小组讨论。


- -

Lew Pitcher


Master Code Code& JOAT-in-training |可根据要求提供GPG公钥

注册Linux用户#112576( http:/ /counter.li.org/

Slackware - 因为我知道我在做什么。

----- BEGIN PGP SIGNATURE-- ---

版本:GnuPG v1.2.7(GNU / Linux)

iD8DBQFD6XIYagVFX4UWr64RAh0mAKC4EvbxujznOuD34nIsFp AyqQdLWgCgwF4w

mYIGfRtyjAhmUM8LaQ158MY =

= hIYb

----- END PGP SIGNATURE -----



It isn''t implemented as a C function. It is implemented as an operating system
call wrapped in a C function. It is the operating system that performs the
magic of causing fork()s return value to differ depending on the process.

As such, this magic is off-topic for comp.lang.c and should be discussed in
some other group.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I''m doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFD6XIYagVFX4UWr64RAh0mAKC4EvbxujznOuD34nIsFp AyqQdLWgCgwF4w
mYIGfRtyjAhmUM8LaQ158MY=
=hIYb
-----END PGP SIGNATURE-----


这篇关于fork实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆