Browse Source

add lec7-2 fork.c in related_info

main
chyyuu 11 years ago
parent
commit
2677bc9b8d
2 changed files with 20 additions and 1 deletions
  1. +5
    -1
      related_info/lec7-8/Makefile
  2. +15
    -0
      related_info/lec7-8/lec7_2-fork.c

+ 5
- 1
related_info/lec7-8/Makefile View File

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

+ 15
- 0
related_info/lec7-8/lec7_2-fork.c 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);
}
}

||||||
x
 
000:0
Loading…
Cancel
Save