From 2677bc9b8dfba71fa28042d1de05047c2b10d024 Mon Sep 17 00:00:00 2001
From: chyyuu <chyyuu@k750s>
Date: Thu, 17 Oct 2013 09:09:27 +0800
Subject: [PATCH] add lec7-2 fork.c in related_info

---
 related_info/lec7-8/Makefile      |  6 +++++-
 related_info/lec7-8/lec7_2-fork.c | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 related_info/lec7-8/lec7_2-fork.c

diff --git a/related_info/lec7-8/Makefile b/related_info/lec7-8/Makefile
index 149e0bb..1206560 100644
--- a/related_info/lec7-8/Makefile
+++ b/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
diff --git a/related_info/lec7-8/lec7_2-fork.c b/related_info/lec7-8/lec7_2-fork.c
new file mode 100644
index 0000000..be62392
--- /dev/null
+++ b/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);
+  }
+}