2016年3月24日 星期四

Python Language , using "ps" and "grep" to find the processes and kill

#!/usr/bin/python
import subprocess, re
from subprocess import Popen
from subprocess import PIPE

keyword = "sample"  # Setting "grep" keyword
ptn = re.compile("\s+")

p1 = Popen(["ps", "-aux"], stdout=PIPE)
p2 = Popen(["grep", keyword], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
print("Output:\n{0}".format(output))
lines = output.strip().split("\n")
for line in lines:
    items = ptn.split(line)
    print("kill {0}...".format(items[1], subprocess.call(["kill", items[1]])))

沒有留言:

Blocking software access to the Internet

  第一個步驟先打開控制台   在右上角搜尋防火牆 點擊 Windows 防火牆 再點擊左邊下面有個進階設定 會出現以下 點擊左邊輸入規則 再點擊新增規則 點擊程式直接下一步   選擇要禁止的程式 在點下一步 ...