kill childs
Donn Cave
donn at u.washington.edu
Wed Feb 27 17:09:32 EST 2002
Quoth martin at v.loewis.de (Martin v. Loewis):
| "Christian Schmidt" <christian.schmidt at REMOVEaifb.uni-karlsruhe.de> writes:
|> I use Python to start other commands via os.system("cmdline")
|> When I kill the script with 'kill <scriptpid>' the command is not killed,
|> only the script.
|> How can I kill the child, too?
|> Can I use something like os.kill(-1) in an except-statement?
| If you use os.system, you cannot find out what the pid of the child
| is. So as a prerequisite, you need to replace the call to system()
| with a fork/exec sequence. Then, you can install a signal handler
| (using signal.signal) to kill the subprocesses if any.
He's aiming at the process group, which is a good idea. os.kill(-1, sig)
will work, though of course the signal will be delivered to the calling
process as well. It might be a good idea to set a flag indicating that
the process group kill has already happened, to avoid an infinite loop.
If for some reason a PID is needed, os.spawnv(os.P_NOWAIT, ...) returns it.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list