python - obtaining pid of child process -
i using python's multiprocessing module spawn new process
as follows :
import multiprocessing import os d = multiprocessing.process(target=os.system,args=('iostat 2 > a.txt',)) d.start()
i want obtain pid of iostat command or command executed using multiprocessing module
when execute :
d.pid
it gives me pid of subshell in command running .
any valuable .
thanks in advance
similar @rakslice, can use psutil:
import signal, psutil def kill_child_processes(parent_pid, sig=signal.sigterm): try: parent = psutil.process(parent_pid) except psutil.nosuchprocess: return children = parent.children(recursive=true) process in children: process.send_signal(sig)
Comments
Post a Comment