当前位置: 技术问答>linux和unix
紧急求助——一道去年清华考研操作系统的unix编程题目
来源: 互联网 发布时间:2015-01-21
本文导语: 给出下列程序的输出结构,并说明为什么 #include "studio.h" int main(void) { int I; int IntVariableA,IntVariableB; IntVariableA=100; IntVariableB=200; while((I=fork()==-1); printf("Test..."); if(I!=0) {...
给出下列程序的输出结构,并说明为什么
#include "studio.h"
int main(void)
{
int I;
int IntVariableA,IntVariableB;
IntVariableA=100;
IntVariableB=200;
while((I=fork()==-1);
printf("Test...");
if(I!=0)
{
printf("It is parent process.n");
IntVariableA+=IntVariableB;
wait(null);
printf("In parent: A=%d,B=%dn",IntVariableA,IntVariableB);
printf("My child process,ID number %d exited.n",I);
exit();
}
else
{
printf("It is child process.n");
IntVariableB+=IntVariablea;
printf("In child: A=%d,B=%dn",IntVariableA,IntVariableB);
}
printf("It is child or parent process.n");
exit()
}
#include "studio.h"
int main(void)
{
int I;
int IntVariableA,IntVariableB;
IntVariableA=100;
IntVariableB=200;
while((I=fork()==-1);
printf("Test...");
if(I!=0)
{
printf("It is parent process.n");
IntVariableA+=IntVariableB;
wait(null);
printf("In parent: A=%d,B=%dn",IntVariableA,IntVariableB);
printf("My child process,ID number %d exited.n",I);
exit();
}
else
{
printf("It is child process.n");
IntVariableB+=IntVariablea;
printf("In child: A=%d,B=%dn",IntVariableA,IntVariableB);
}
printf("It is child or parent process.n");
exit()
}
|
Test ...
It is child process.
In Child:A=100,B=300
It is child or parent process.
Test...
It is parent process.
In parent: A=300,B=200
My child process,ID number 未知 exited.
It is child process.
In Child:A=100,B=300
It is child or parent process.
Test...
It is parent process.
In parent: A=300,B=200
My child process,ID number 未知 exited.
|
Test...It is child process.
In child: A=100,B=300
It is child or parent process.
Test...It is parent process.
In parent: A=300,B=200
My child process,ID number I exited.(I 是具体系统分配的进程号)
In child: A=100,B=300
It is child or parent process.
Test...It is parent process.
In parent: A=300,B=200
My child process,ID number I exited.(I 是具体系统分配的进程号)