h****a 发帖数: 70 | 1 【 以下文字转载自 Linux 讨论区 】
发信人: himdca (how are you doing?), 信区: Linux
标 题: 再问个fork的题
发信站: BBS 未名空间站 (Thu Jun 9 03:31:30 2011, 美东)
Given the following code:
#include
int main(void)
{
int tmp;
tmp = fork();
if(tmp == 0)
{
printf("Hello ")
sleep(1)
}
else if(tmp > 0)
{
printf("World, ")
sleep(1)
}
print "Bye bye"
}
Assuming the call to fork doesn't fail, which of the following is true (zero
or more answers may be correct):
a The execution of this is deterministic.
b The output will be: 'Hello World, Bye bye'
c This can fail if STDERR is not redirected correctly.
d This will create a child process.
e The output will be: 'Hello Bye bye'
f The print of 'Bye bye' will be executed multiple times.
c是对的吗?不太明白是什么意思。 |
s******n 发帖数: 226 | |
h****a 发帖数: 70 | 3 "c This can fail if STDERR is not redirected correctly."
应该是不对的吧?
【在 s******n 的大作中提到】 : http://hi.baidu.com/yinchao1217/blog/item/13f6a6f4bfdb8c2c730ee
|
m********l 发帖数: 4394 | 4 d, f.
【在 h****a 的大作中提到】 : "c This can fail if STDERR is not redirected correctly." : 应该是不对的吧?
|
s******n 发帖数: 226 | 5 Ding
其实就是各执行一次。 各自输出,各有一个byebye。
但是child先走了一遍
【在 m********l 的大作中提到】 : d, f.
|
h****a 发帖数: 70 | 6 how about c?
【在 m********l 的大作中提到】 : d, f.
|
m********l 发帖数: 4394 | 7 false
【在 h****a 的大作中提到】 : how about c?
|
f****4 发帖数: 1359 | 8 这个代码无法保证child还是parent先走
取决于os调度
有兴趣可以去查一下advanced programming in Unix Env
【在 s******n 的大作中提到】 : Ding : 其实就是各执行一次。 各自输出,各有一个byebye。 : 但是child先走了一遍
|