ʵ
来自「清华大学出版社<linux c编程>的配套代码」· 代码 · 共 21 行
TXT
21 行
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
main()
{
pid_t pc,pr;
pc=fork();
if(pc<0) /* 如果出错 */
printf("error ocurred!\n");
else if(pc==0){ /* 如果是子进程 */
printf("This is child process with pid of %d\n",getpid());
sleep(10); /* 睡眠10秒钟 */
}
else{ /* 如果是父进程 */
pr=wait(NULL); /* 在这里等待 */
printf("I catched a child process with pid of %d\n"),pr);
}
exit(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?