add lec7-2 fork.c in related_info

This commit is contained in:
chyyuu 2013-10-17 09:09:27 +08:00
parent a0e2e3c313
commit 2677bc9b8d
2 changed files with 20 additions and 1 deletions

View File

@ -1,4 +1,8 @@
all: lec7_1.c all: lec7_1.c
@echo "====================================="
@echo "compile and analysis lec7_2"
@echo "====================================="
gcc -g -o lec7_2 lec7_2-fork.c
@echo "=====================================" @echo "====================================="
@echo "compile and analysis lec7_1" @echo "compile and analysis lec7_1"
@echo "=====================================" @echo "====================================="
@ -18,4 +22,4 @@ all: lec7_1.c
process_state: process_state:
top top
clean: clean:
rm ./lec7_1 rm ./lec7_1 ./lec7_2

View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <unistd.h>
void main(void){
int child_status, exec_status;
int pid = fork(); //create a child
if (pid==0) { // child continues here
printf("Child: EXEC lec7_1\n");
exec_status=execve("lec7_1",NULL,NULL);
printf("Child: Why would I execute?\n");
} else { // parent continues here
printf("Parent: Whose your daddy?\n");
child_status=wait(pid);
printf("Parent: the child %d exit with %d\n",pid, child_status);
}
}