cron: use prctl to set process name & title (#2524)

This commit is contained in:
Frédéric Péters 2013-02-22 09:15:20 +01:00 committed by Thomas NOEL
parent 57ffd032b2
commit dfa5675d82
1 changed files with 6 additions and 13 deletions

View File

@ -18,9 +18,9 @@ import os
import signal
import time
try:
import dl
import prctl
except ImportError:
dl = None
prctl = None
import sys
parent_killed = False
@ -88,17 +88,10 @@ def spawn_cron(create_publisher):
cron_pid = os.fork()
if cron_pid == 0:
pub = create_publisher()
# set process name, this only works on Linux, 15 == PR_SET_NAME
if dl:
try:
libc = dl.open('/lib/libc.so.6')
except dl.error:
pass
else:
try:
libc.call('prctl', 15, os.path.basename(sys.argv[0]) + ' [cron]\0', 0, 0, 0)
except ValueError: # missing symbol
pass
# set process name and title (this only works on Linux)
if prctl:
prctl.set_name(os.path.basename(sys.argv[0]) + ' [cron]')
prctl.set_proctitle(os.path.basename(sys.argv[0]) + ' [cron]')
signal.signal(signal.SIGTERM, stop_cron_process)
cron(pub)
sys.exit(0)