zombie-process

How to avoid read() from hanging in the following situation?

邮差的信 提交于 2019-12-24 05:26:15
问题 I have some code that forks a third-party application and redirects its standard output to the parent process, roughly as follows (no error handling here for brevity): char* args[] = {"/path/to/3rd/party/binary", "with", "args", NULL}; int fds[2]; pipe2(fds, O_CLOEXEC); pid_t pid = fork(); if (pid == 0) { dup2(fds[1], STDOUT_FILENO); execvp(args[0], args); _exit(1); } else { close(fds[1]); char buf[1024]; int bytes_read; while ((bytes_read = read(fds[0], buf, sizeof buf - 1)) > 0) { buf[bytes

How to determine the state of a process (i.e. if it is a zombie)

最后都变了- 提交于 2019-12-22 18:34:26
问题 how can I get information on the state of a process (i.e. if it is a zombie) using C under Linux? After reading the answers so far I want to narrow my question somewhat: I would prefer a pure C solution. After reading the ps source (which reads /proc/) I thought that there should be a better way and asked here :) 回答1: You'll want to learn about interacting with the /proc/ "psuedo-filesystem" via typical C standard library calls. The documentation necessary to get started is included with any

killing child processes at parent process exit

喜欢而已 提交于 2019-12-22 16:36:31
问题 I'm very new to c and programming and need some help. In c on linux(cygwin) I am required to remove all child processes at exit. I have looked at the other similar questions but can't get it to work. I've tried- atexit(killzombies); //in parent process void killzombies(void) { printf("works"); kill(0, SIGTERM); printf("works"); if (waitpid(-1, SIGCHLD, WNOHANG) < 0) printf("works"); } for some reason, "works" doesn't even print ever. I press ctrl + c to exit. ALSO I have tried- prctl(PR_SET

killing child processes at parent process exit

那年仲夏 提交于 2019-12-22 16:34:03
问题 I'm very new to c and programming and need some help. In c on linux(cygwin) I am required to remove all child processes at exit. I have looked at the other similar questions but can't get it to work. I've tried- atexit(killzombies); //in parent process void killzombies(void) { printf("works"); kill(0, SIGTERM); printf("works"); if (waitpid(-1, SIGCHLD, WNOHANG) < 0) printf("works"); } for some reason, "works" doesn't even print ever. I press ctrl + c to exit. ALSO I have tried- prctl(PR_SET

read() hangs on zombie process

依然范特西╮ 提交于 2019-12-22 13:01:05
问题 I have a while loop that reads data from a child process using blocking I/O by redirecting stdout of the child process to the parent process. Normally, as soon as the child process exits, a blocking read() in this case will return since the pipe that is read from is closed by the child process. Now I have a case where the read() call does not exit for a child process that finishes. The child process ends up in a zombie state, since the operating system is waiting for my code to reap it, but

What's the reason for cookies mysteriously reappearing?

不想你离开。 提交于 2019-12-22 10:56:14
问题 I'm developing a web application using a cookie to store session information. I've manually deleted the session cookies because I'm working on another part of the code where I don't want a login session. However, after a couple reloads of the page, the session cookie mysteriously reappears, including an earlier cookie that I had only set once for testing purposes, then deleted and never used again. I keep manually deleting the cookies in question, but still, when I reload the page after a

How to use Popen to run backgroud process and avoid zombie?

百般思念 提交于 2019-12-22 09:10:13
问题 I've a listener server running new thread to for each client handler. Each handler can use: proc = subprocess.Popen(argv, executable = "./Main.py", stdout = _stdout, stderr = subprocess.STDOUT, close_fds=False) to run new process in background, after what the handler thread is ended. After the background process is ended, it is kept in Z state. Is it possible to ask subprocess.Popen() to handle SIG_CHILD to avoid this zombie? I don't want to read process state using proc.wait(), since for

UNIX Zombies and Daemons

梦想的初衷 提交于 2019-12-22 04:26:16
问题 I understand that a zombie is created when a process doesn't clean-up well (its resources aren't reclaimed/reaped). After calling fork() to create a new process, the parent should always call waitpid on that process to clean it up. I also have learned that a daemon is created by forking a child that was itself created by fork, and then letting the child die. Apparently the init process (pid #1) in UNIX would take custody of the process once you do this. What I want to know is - as far as I

Starting a daemon from PHP

两盒软妹~` 提交于 2019-12-21 08:00:07
问题 For a website, I need to be able to start and stop a daemon process. What I am currently doing is exec("sudo /etc/init.d/daemonToStart start"); The daemon process is started, but Apache/PHP hangs. Doing a ps aux revealed that sudo itself changed into a zombie process, effectively killing all further progress. Is this normal behavior when trying to start a daeomon from PHP? And yes, Apache has the right to execute the /etc/init.d/daemonToStart command. I altered the /etc/sudoers file to allow

R parallel computing and zombie processes

自闭症网瘾萝莉.ら 提交于 2019-12-20 10:33:28
问题 This is basically a follow up to the this more specialized question. There have been some posts about the creation of zombie processes when doing parallel computing in R : How to stop R from leaving zombie processes behind How to kill a doMC worker when it's done? Remove zombie processes using parallel package There are several ways of doing parallel computing and I will focus on the three ways that I have used so far on a local machine. I used doMC and doParallel with the foreach package on