PDA

View Full Version : [Python 3] Having trouble stopping a process



DustyMP
July 5th, 2009, 03:29 AM
I'm trying to write a script for some programs I run routinely. The problem is that one is run in the terminal and only exits with a ctrl+c. I just can't manage to figure out how to pass it along. Everything I've tried so far interrupts it for half a second or so and it just keeps trucking along. The latest evolution looking something like:



import subprocess as sub, time
test = sub.Popen(['sudo airodump-ng mon0'], shell=True)
time.sleep(120)
test.terminate()


I'm trying to learn this language so I can move away from VBScript so any nudges in the right direction would be greatly appreciated =)

sub2007
July 5th, 2009, 04:13 PM
Have you tried sending a SIGKILL, SIGTERM or SIGABRT using send_signal()?

Otherwise, use os.system to execute a process kill using any relevant command that works.

snova
July 6th, 2009, 01:46 AM
If it exits on Ctrl-C, send SIGINT.



import signal, subprocess, time

test = subprocess.Popen(["sudo airodump-ng mon0"], shell=True)
time.sleep(120)
test.send_signal(signal.SIGINT)

p0cky84
July 6th, 2009, 02:52 AM
Kill it, kill it with fire! aka. killall python(3?)

Empire537
July 6th, 2009, 06:56 AM
Just use:


import os
os.system('kiill processID')
or if you don't have your processID



import os
os.system('killall myprocessname')

sub2007
July 7th, 2009, 08:58 PM
^You'll be able to get the pid from "test.pid" :)

DustyMP
July 13th, 2009, 01:11 PM
Thanks all of you, killing it with the PID worked =)