changing process name

A

andrea crotti

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top