以下程序的输出结果是()#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
哪种进程之间的通信,数据不可以重复读( )
A. 共享内存映射进程间通信
B. fifo
C. 管道
D. 文件