对于如下C语言程序 int main() { pid_t pid; int x=1; pid = fork(); if(pid==0) printf("I am the child process, x=%d\n", ++x); else printf("I am the parent process, x=%d\n", --x); } 在UNIX操作系统中正确编译链接后,其正确的运行结果是
A.I am the child process, x=2
B.I am the parent process, x=0
C.I am the parent process, x=2
D.I am the child process, x=0
第1题:
请选出以下程序的输出结果_______。 #include<stdio.h> sub(int*s,inty) { static int t=3, y=s[t];t-; } main() { int a[]={1,2,3,4},i,x=0; for(i=0;i<4;i++){ sub(a,x);printf("%d",x);} printf("\n"); }
A.1234
B.4321
C.0
D.4444
第2题:
请选出以下程序的输出结果( )。 #include <stdio.h> sub(int *s,int y) { static int t=3; y=s[t];t--; } main() { int a[]={1,2,3,4},i,x=0; for(i=0;i<4;i++) { sub(a,x);printf("%d",x); } printf("\n"); }
A.1234
B.4321
C.0
D.4444
第3题:
UNIX操作系统中,fork()系统调用用于创建进程。仔细阅读、分析下列程序,假设程序正确运行并创建子进程成功,那么,输出到屏幕的正确结果是main() { pid_t pid; pid = fork(); if (pid = = 0) printf ("Hello World\n"); else if (pid >0) printf ("Hello World\n"); else printf ("Hello World\n"); }
A.什么都没有
B.1行Hello World
C.2行Hello World
D.3行Hello World
第4题:
嵌入式Linux操作系统中任务的创建过程如下,以下说法正确的是(53)。
void main( )
{ int pid;
pid= fork( )
if(pid>0)
printf("parent task");
else if(pid= =0)
{ printf("child task") ;
execvp ("MyTash", NULL);
}
}
A.子任务的创建基于fork/exec模型
B.子任务的创建基于spawn模型
C.先为子任务分配内存空间,再分配相应的数据结构
D.直接为子任务分配一个全新的地址空间,然后再将其代码装入运行
第5题:
有以下程序:#include <stdio.h>void f(int * x,int * y) int t; t= *x; *x= *y; *y=t;main ( ){ int a[8] = { 1,2,3,4,5,6,7,8} ,i, * p, * q; p=a;q =&a[7]; while(p<q) { f(p,q) ;p ++ ;q --; } for(i =0;i<8;i ++ ) printf(" % d," ,a[i]); }程序运行后的输出结果是( )。
A.8,2,3,4.,5,6,7,1,
B.5,6,7,8,1,2,3,4,
C.1,2,3,4,5,6,7,8,
D.8,7,6,5,4,3,2,1,