changing process name

andrea crotti andrea.crotti.0 at
Mon Nov 19 11:39:29 CET 2012

I have very long processes to spawn which I want to lauch as separate
processes (and communicate with ZeroMQ), but now the problem is that the
forked process appears in "ps" with the same name as the launcher

This is a simplified version of what I'm trying to do:

import sys
from os import fork, _exit

def on_forked_process(func):
    """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)
            return pid

    return _on_forked_process

def start_long_proc():
    sys.argv[:] = [sys.argv[0]] + ['daemon', 'arguments']
    from daemon import long_sleep

if __name__ == '__main__':
    # if the main process is still running but it's not told the child
    # when it dies then it becomes a zombie?? no apparently it doesn't
    while True:

import sys
import time

def long_sleep():
    sys.argv[:] = [sys.argv[0]] + ['daemon', 'arguments']

so both the sys.argv reassignment don't work so far, any other way to
fix this?

On the real machine I also get zombie processes, but on my machine I
can't reproduce this, and would also be nice to fix that..


More information about the Python-list mailing list