#include <> #include <> #include <> main() { int p; p=fork(); if (p>0) { printf("In the parent\n"); wait(0); } else { printf(“In child, ID=%d\n”,getpid()); printf("before execute execl\n"); execl("./hello","hello",NULL); perror("execl failed to run hello"); printf("after execute execl\n"); } } 三、实验步骤及运行结果分析 (p32页),把运行结果截图。 再把_exit(0)换为exit(0),运行程序,把运行结果截图。 (1)分析修改前后运行结果出现的差异。 当为_exit(0)的时候,运行结果为: this is parent1this is parent2 this is parent1this is child first 当为exit(0)的时候,运行结果为: this is parent1this is parent2 this is parent1this is child first this is child second 第二个运行结果比较第一个运行结果,多了一行:this is child second (2)分析exit(0)和_exit(0)的区别。 _exit()和exit()主要区别是一个直接结束进程进入内核