terminating zombie processes (forked)
ive found this code on "Advanced Linux Programming - Chapter 3 : Processes" it should terminate fork()ed processes after they done their job
but it doesnt, as soon as the forked processes finishes its job and calls exit, the whole application restarts :/ here is the code Code:
#include <signal.h> Code:
if (fork() == 0) |
Hey mate, I just tried your app and it works fine ...
Try this .... to make things clear Code:
int main() { |
yea, but with ur method ill have to call the cleanup code reguraly, im trying to get the one i posted to work since the forked processes sends a SIGCHLD signal whenever it finishes working. so its not blocking any of the app functions.
thanks. EDIT: this app should sleep for 100 seconds, but it doesnt :/ Code:
#include <signal.h> |
Yes you are right , I just wanted to demonstrate the use of the macros WIFEXITED and EXITSTATUS for debugging your code.
Like I said , I ran your code and it works just fine on my system. |
the last one i posted? does it sleep for 100 seconds? cause it exits right away from my terminal :S
|
Quote:
Code:
sleeptime = 100; |
its not just sleep, any function i do, such as receiving file from http server, it restarts the whole application as soon as the download (forked process) completes !!
|
I ran your test code replacing sleep with the while loop I provided and it sleeps the whole time.
What are you doing in the parent process? I assume you have a loop doing something? what is the exit condition of the loop? Other system calls are affected by signals and need to be 'restarted' after a signal occurs in a process. |
even socket calls? like recv?
and yea, ive a loop in the forked process and a loop in the parent process.... |
Yes sys calls like recv will return on a signal.
See the man page (http://linux.die.net/man/3/recv), one of the possible errno value it sets is EINTR. somethng like this handles it. Code:
errno = 0 |
ok, i can do something like that, one more question, is there is no other way to make it uninterrupted? maybe a something when assigning the signal handler? or there is no way to evade the interruption without modifiying recv()?
|
Hello KillerCode,
I tested your original sleep(100)-Code. It works fine. Must really have to do something with your parents process. Greetings Bernd |
What I showed is a pretty standard way of dealing with it as it will work everywhere and always.
Take a look at the man page for signal (http://www.kernel.org/doc/man-pages/.../signal.7.html) for a info on signals and interruptable system calls. On linux you can possible use SA_RESTART with your signal handler, but it doesn't all interruptable system calls. You'll notice on the man page that SA_RESTART works for recv, depending on how it is called. |
All times are GMT -5. The time now is 03:07 PM. |