still get a <defunct> using a python script in the crontab

martijn at gamecreators.nl martijn at gamecreators.nl
Wed Sep 19 06:02:17 EDT 2007


H!

I have made a program that is checking if a program is running or not.
If the program is not running then it must start the program again.

in the /etc/crontab:
*     *       *       *       *       root    /usr/sbin/
program_prgchk

in the /usr/sbin/program_prgchk:
/usr/local/bin/python /home/reseller/domeinaanvraag/program_prgchk.py


in the program_prgchk.py:
----------------------------------------
import string
import os
import commands

def checkifrunning():
    line = string.strip(commands.getoutput("ps x -o pid,command | grep
program_reseller.py | grep -v 'grep'"))
    pid = string.split(line,' ')[0]
    if pid<>'':pid = int(pid)
    return pid

if checkifrunning()=='':
    os.system('/usr/sbin/program_reseller')
#    os.wait()
#    os.waitpid(checkifrunning(),0)

os._exit(0)


If I run the command /usr/sbin/program_prgchk everything works (no
<defunct> process)
But when I use it in the crontab I get a <defunct> process

Thanks for helping,
GC-Martijn




More information about the Python-list mailing list