如何避免僵尸进程
来源:互联网 发布:电话变声软件 编辑:程序博客网 时间:2024/05/19 20:42
最近总是会遇到僵尸进程,很烦恼,于是博主就阅览群书,终于找到了这种方法:
调用fork两次就好了!代码如下:
#include "apue.h"#include <sys/wait.h>intmain(void)...{ pid_t pid; if ((pid = fork()) < 0) ...{ err_sys("fork error"); } else if (pid == 0) ...{ /**//* first child */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid > 0) exit(0); /**//* parent from second fork == first child */ /**//* * We're the second child; our parent becomes init as soon * as our real parent calls exit() in the statement above. * Here's where we'd continue executing, knowing that when * we're done, init will reap our status. */ sleep(2); printf("second child, parent pid = %d ", getppid()); exit(0); } if (waitpid(pid, NULL, 0) != pid) /**//* wait for first child */ err_sys("waitpid error"); /**//* * We're the parent (the original process); we continue executing, * knowing that we're not the parent of the second child. */ exit(0);}
0 0
- 如何避免僵尸进程
- 如何避免僵尸进程
- 如何避免成为僵尸进程
- 僵尸进程以及如何避免
- 如何避免产生僵尸进程
- fork两次如何避免僵尸进程
- fork两次如何避免僵尸进程
- fork两次如何避免僵尸进程收藏
- 如何避免Linux的僵尸进程
- Linux 僵尸进程产生及如何避免
- fork两次如何避免僵尸进程收藏
- fork两次如何避免僵尸进程
- Linux僵尸进程产生及如何避免
- fork两次如何避免僵尸进程收藏
- fork两次如何避免僵尸进程
- fork两次如何避免僵尸进程
- fork两次如何避免僵尸进程收藏
- Linux僵尸进程产生及如何避免
- 黑马程序员5--JavaScript 基础
- Pat(Advanced Level)Practice--1026(Table Tennis)
- 搜索引擎优化-排除重复内容
- Listview 软引用SoftReference异步加载图片
- uboot编译
- 如何避免僵尸进程
- 黑马程序员6--HTML
- nyoj219
- ntp esxi
- js:深入函数的定义
- FZU2171:防守阵地 II(线段树)
- 第五周作业——Dijkstra算法的实现
- POP3、SMTP和IMAP
- 黑马程序员7--单例设计模式