I am starting snmpd with subprocess, storing a reference to this as a global variable, then want to kill this process later on.
I start the process like so:
snmp_proc = subprocess.Popen(['snmpd', '-p', pid_file,'-Lf', log_file],
stdout=open(os.devnull,'w'),stderr=subprocess.STDOUT)
This starts correctly but seems to also create some sort of zombie process? ps ax output gives:
1716 ? Z 0:00 [snmpd] <defunct>
1718 ? S 0:00 snmpd -p /var/run/snmpd.pid -Lf /var/log/snmpd
Now when I try to kill the process later only the defunct zombie process is killed, with the other process remaining. Any idea what I'm doing wrong? Here is the code to stop snmpd:
def stop_snmp():
global snmp_proc
if not snmp_proc:
return
snmp_proc.terminate()
snmp_proc.wait()
snmp_proc = None