forking and avoiding zombies!

A

andrea crotti

So I implemented a simple decorator to run a function in a forked
process, as below.

It works well but the problem is that the childs end up as zombies on
one machine, while strangely
I can't reproduce the same on mine..

I know that this is not the perfect method to spawn a daemon, but I
also wanted to keep the code
as simple as possible since other people will maintain it..

What is the easiest solution to avoid the creation of zombies and
maintain this functionality?
thanks


def on_forked_process(func):
from os import fork
"""Decorator that forks the process, runs the function and gives
back control to the main process
"""
def _on_forked_process(*args, **kwargs):
pid = fork()
if pid == 0:
func(*args, **kwargs)
_exit(0)
else:
return pid

return _on_forked_process
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top