-
Notifications
You must be signed in to change notification settings - Fork 2
/
killprocess.py
39 lines (30 loc) · 875 Bytes
/
killprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# Author: Pedram Tavazohi
import psutil
import sys
import time
import datetime
import os
user = os.getenv("USER")
def check_proccess(name):
"""
"""
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if name.lower() in proc.name().lower() and proc.username() == user:
now = datetime.datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"), proc.pid, proc.name())
proc.kill()
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
if len(sys.argv) < 2:
print("Please input a list of process names")
exit()
while True:
for arg in sys.argv[1:]:
print(arg)
check_proccess(arg)
time.sleep(30)