-
Notifications
You must be signed in to change notification settings - Fork 0
/
psutil_Gev.py
38 lines (29 loc) · 943 Bytes
/
psutil_Gev.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
import psutil
class MyProcess:
def __init__(self, name):
self.name = name
def get_pid(self, name):
self.name = name
for process in psutil.process_iter():
if process.name() == name:
return process.pid
def kill_process_by_id(self, name):
self.name = name
for process in psutil.process_iter():
if process.name() == name:
process.kill()
def check_proc_run(self, name):
pid = self.get_pid(name)
self.name = name
for process in psutil.process_iter():
if process.status() == "running" and process.pid == pid:
return True
return False
def start_proc_by_name(self, name):
self.name = name
os.system("start %s" + name)
name1 = "notepad.exe"
p = MyProcess(name1)
print(p.get_pid(name1))
print(p.kill_process_by_id(name1))
print(p.check_proc_run(name1))