判断题
下面的代码,只会有一个判断输出,要么是子进程,要么是父进程:
#include
#include
#include
int main(int argc, char * argv[])
{
int pid;
/* fork another process */
pid = fork();
if (pid < 0)
{
/* error occurred */
fprintf(stderr,"Fork Failed!");
exit(-1);
}
else if (pid == 0)
{
/* child process */
printf("This is Child Process!");
}
else
{
/* parent process */
printf("This is Parent Process!");
/* parent will wait for the child to complete*/
wait(NULL);
printf("Child Complete!");
}
}
答案:
错误