一个进程调用 wait 或 waitpid 函数,可能产生 3 中情况,下列不属于这 3 种情况的是 ( )。
A. 如果所有子进程都还在运行,进程挂起。
B. 如果恰有子进程结束,它的终止状态字正等待父进程提取,立即得到该终止状态字并返回,其返回值为该子进程的进程号。
C. waitpid,如果该进程没有子进程,参3指定了WNOHANG,返回0。
D. 如果该进程没有子进程,立即返回,返回值为 0。
以下程序的输出结果是()#include #include #include #include #include int main(int argc, char *argv[]){printf("===================start of file\n");pid_t pid = fork();if (pid == -1) {perror("fork error");exit(1);} else if (pid == 0) {printf("---child,my pid is %d,my parent pid is %d\n",getpid(),getppid());} else if (pid > 0) {printf("---parent my child is %d,my pid is %d,myparent pid is %d\n", pid,getpid(),getppid());sleep(1);}printf("===================end of file\n");return 0;}
A. ===================start of file---parent my child is 4759,my pid is 4758,myparent pid is 3700---child,my pid is 4759,my parent pid is 4758===================end of file
B. ===================start of file---parent my child is 4759,my pid is 4758,myparent pid is 3700---child,my pid is 4759,my parent pid is 4758===================end of file===================end of file
C. ===================start of file---parent my child is 4759,my pid is 4758,myparent pid is 3700---child,my pid is 4759,my parent pid is 4758===================end of file===================end of file===================end of file
D. ===================start of file===================start of file---parent my child is 4759,my pid is 4758,myparent pid is 3700---child,my pid is 4759,my parent pid is 4758===================end of file===================end of file
以下程序输出结果是( )#include #include #include int var = 100;int main(void){pid_t pid;pid = fork();if (pid == -1) {perror("fork error");exit(1);} else if (pid > 0) {var = 288;printf("parent, var = %d\n", var);sleep(1);} else if (pid == 0) {printf("child, var = %d\n", var);}printf("------------finish---------------\n");return 0;}
A. parent, var = 288child, var = 100------------finish---------------
B. parent, var = 288child, var =288------------finish---------------------------finish---------------
C. parent, var = 288child, var = 100------------finish---------------------------finish---------------
D. parent, var = 288child, var = 288------------finish---------------------------finish---------------
以下程序输出结果是()int var = 100;int main(void){int *p;pid_t pid;int fd;fd = open("temp", O_RDWR|O_CREAT|O_TRUNC, 0644);if(fd < 0){perror("open error");exit(1);}ftruncate(fd, 4);p = (int *)mmap(NULL, 4, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);if(p == MAP_FAILED){perror("mmap error");exit(1);}close(fd);pid = fork();if(pid == 0){*p = 7000;var = 1000;printf("child, *p = %d, var = %d\n", *p, var);} else {sleep(1);printf("parent, *p = %d, var = %d\n", *p, var);wait(NULL);int ret = munmap(p, 4);if (ret == -1) {perror("munmap error");exit(1);}}return 0;}
A. child, *p = 7000, var = 1000parent, *p = 0, var = 100
B. child, *p = 7000, var = 1000parent, *p = 7000, var = 100
C. child, *p = 7000, var = 1000parent, *p = 7000, var = 1000
D. child, *p = 7000, var = 1000parent, *p = 0, var = 1000