소스 검색

add lec7-2 fork.c in related_info

main
chyyuu 12 년 전
부모
커밋
2677bc9b8d
2개의 변경된 파일20개의 추가작업 그리고 1개의 파일을 삭제
  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 파일 보기

@ -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 파일 보기

@ -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);
}
}

불러오는 중...
취소
저장