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是对的吗?不太明白是什么意思。 | h********8 发帖数: 7355 | 2 "Assuming the call to fork doesn't fail", c就是错的。
应该check tmp==-1(fork failed)。 | s**********o 发帖数: 197 | 3 感觉就是shell里redirect stderr到一个文件,打开文件失败对你程序有没有影响,答
案是没影响,所以C不对 | j*******d 发帖数: 8834 | 4 d,f
【在 h****a 的大作中提到】 : 【 以下文字转载自 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();
|
|