借用csapp中对fork,进程的理解。
代码如下:
//fork函数代码如下
#include <unistd.h>
int Fork(int argc, char *argv[]) {
int pid;
/* fork another process */
pid = fork();
if (pid<0) {
/* error occurred */
fprintf(stderr,"Fork Failed!");
exit(-1);
} else if (pid==0) {
/* child process */
printf("This is Child Process!\n");
} else {
/* parent process */
printf("This is Parent Process!\n");
/* parent will wait for the child to complete*/
wait(NULL);
printf("Child Complete!\n");
}
}
//在main函数中写入如下代码
MenuConfig("fork","Fork a new process",Fork);
1.代码放入menuos
2.开始gdb调试
3.结果