changing process name

Discussion in 'Python' started by andrea crotti, Nov 19, 2012.

  1. 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
    process.

    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)
    _exit(0)
    else:
    return pid

    return _on_forked_process


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


    if __name__ == '__main__':
    start_long_proc()
    # 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:
    pass


    Where daemon.py:
    import sys
    import time


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


    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..

    Thanks
    andrea crotti, Nov 19, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. herman
    Replies:
    5
    Views:
    306
    Karthik Gurusamy
    Sep 5, 2007
  2. Tim Johnson
    Replies:
    0
    Views:
    193
    Tim Johnson
    Mar 12, 2011
  3. 12345678 123456789

    Application Name / Process Name

    12345678 123456789, May 21, 2010, in forum: Ruby
    Replies:
    3
    Views:
    97
    Mark T
    May 24, 2010
  4. perlcoder

    get process name from process id

    perlcoder, Jul 17, 2008, in forum: Perl Misc
    Replies:
    2
    Views:
    400
    Ted Zlatanov
    Jul 17, 2008
  5. Adam Tauno Williams

    Re: changing process name

    Adam Tauno Williams, Dec 30, 2012, in forum: Python
    Replies:
    0
    Views:
    95
    Adam Tauno Williams
    Dec 30, 2012
Loading...

Share This Page