add lec7-2 fork.c in related_info
This commit is contained in:
parent
a0e2e3c313
commit
2677bc9b8d
@ -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
|
||||||
|
15
related_info/lec7-8/lec7_2-fork.c
Normal file
15
related_info/lec7-8/lec7_2-fork.c
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user