僵尸进程和叉子 [英] Zombie process and fork

查看:75
本文介绍了僵尸进程和叉子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码...

i have a code like this...

c = fork();
if(c==0) {
    close(fd[READ]);

    if (dup2(fd[WRITE],STDOUT_FILENO) != -1) 
        execlp("ssh", "ssh", host, "ls" , NULL);
    _exit(1);

}   
close(fd[WRITE]);

fd [READ]和fd [WRITE]是管道文件描述符.

fd[READ] and fd[WRITE] are pipe file descriptors.

当我连续运行它时,当我使用ps ax时会有很多僵尸进程.该如何纠正?这是因为我没有使用父级来等待子进程的退出状态...

when i run it continuously, there are a lot of zombie processes when i use ps ax. How to rectify this? Is this because i am not using the parent to wait for the exit status of the child process...

推荐答案

如果您无意等待 wait 子进程,请将 SIGCHLD 处理程序设置为 SIG_IGN 以使内核自动获得您的孩子,例如

If you have no intention to wait for your child processes, set the SIGCHLD handler to SIG_IGN to have the kernel automatically reap your children, eg.

signal(SIGCHLD, SIG_IGN);

这篇关于僵尸进程和叉子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆