如果(叉())叉()
我正在学习操作系统测验,但我不明白
if(fork())
fork()
会产生什么输出。有人可以解释一下吗?
我不明白这一行:
if(fork())
编辑:
我所说的“输出”的意思是,如果执行此代码,将会有多少个进程。
抱歉我学完有点头晕。
I am studying for an OS quiz and I did not understand what output
if(fork())
fork()
will produce. Can someone explain?
I didn't understand this line:
if(fork())
Edit:
What I meant with "output" is how many processes will be there if this code was executed.
Sorry I'm a bit dizzy after studying.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里有一个提示:
if (fork())
只是if (fork() != 0)
的简短编写方式。Here's a hint:
if (fork())
is just a short way of writingif (fork() != 0)
.也许你最好尝试一下,阅读fork的文档,然后,如果仍然不明白,请就您不明白的部分提出更具体的问题。
首先尝试这个:
Perhaps you are best off just trying it, reading the documentation for fork, and then, if it still doesn't make sense, asking a more specific question about what part you don't understand.
Start by trying this:
我和你有同样的问题。
::::::> 的含义
if (fork())
if (fork() !=0)
,如您所知:fork()
:可以取3个值!fork() = 0
对于子代。<代码>fork() < 0 错误。
<代码>fork()> 0 父级。
所以:
if ( 0 != O )
==> false (在这种情况下,您不必执行 2 fork())if (-123 != 0 )
==>是的(是的,你有)。if (5 != 0)
==>是的(是的,你有)。好喜欢
i had a same problem like you.
the meaning of ::::::>
if (fork())
if (fork() !=0)
, and as you know:fork()
: can take 3 values!fork() = 0
for child.fork() < 0
error.fork() > 0
parent.So:
if ( 0 != O )
==> false (in this case you dont have to do the 2 fork())if (-123 != 0 )
==> True (yes you have).if (5 != 0 )
==> true (yes you have).good like
对于父
进程
和子进程,它的计算结果是:
就是这样:)
for parent
evaluated as
and for child process it is evaluated as:
that is it :)