ya2 · news · projects · code · about

some planning
[pmachines.git] / ya2 / tools / kill_yorg.py
1 # this kills yocto when it is being launched by geany
2 from subprocess import Popen, PIPE
3 from os import system
4
5
6 def exec_cmd(cmd):
7 ret = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate()
8 return '\n'.join(ret)
9
10
11 processes_str = exec_cmd('ps aux | grep "python main.py"')
12 processes = list(enumerate(processes_str.split('\n')))
13 sh_cmd = ' /bin/sh -c python main.py'
14 geany_row = [proc for proc in processes if proc[1].endswith(sh_cmd)][0][0]
15 geany_pid = list(processes)[geany_row + 1][1].split()[1]
16 system('kill -9 ' + geany_pid)