楼主:
shi359 (归人还是过客)
2016-06-25 17:43:50这是清大周志远老师的 os ppt 范例
#include <stdio.h>
void main( ) {
int A;
A = fork();
if(A == 0){
printf(“this is from child process\n”);
execlp(“/bin/ls”, “ls”, NULL);
} else{
printf(“this is from parent process\n”);
int pid = wait(&status);
printf(“Child %d completes”, pid);
}
printf(“process ends %d\n”, A);
}
Output:
this is from child process
this is from parent process
a.out hello.c readme.txt
Child 32185 completes
process ends 32185
想请问 为什么 child 不会印出 process ends 0 呢?
谢谢
作者: aa06697 (todo se andarà) 2016-06-25 23:39:00
楼上看错了吧 不然就是原po打错了那句是在else外面 最下面大括号是main的感觉应该要印吧 你有实际跑过一次程式码