-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_title.py
More file actions
39 lines (32 loc) · 1.03 KB
/
process_title.py
File metadata and controls
39 lines (32 loc) · 1.03 KB
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 python3
# -*- coding: utf-8 -*-
from multiprocessing import Process
import os
import psutil #pip3 install psutil
import setproctitle #pip3 install setproctitle
import sys
import time
def task(name):
time.sleep(3)
print("subprocess name = : ", name)
print(psutil.Process(os.getpid()).name())
os.system("ps axu | grep -v grep | grep {}".format(name))
print()
print()
setproctitle.setproctitle(name)
print("after setproctitle: ", name)
print(psutil.Process(os.getpid()).name())
os.system("ps axu | grep -v grep | grep {}".format(name))
def main():
#<NOTE>just work for 'ps aux | grep mdms';
# NOT by psutil.Process().name(), its just 'python'
setproctitle.setproctitle("test-proc")
print(psutil.Process(os.getpid()).name())
os.system("ps axu | grep -v grep | grep test-proc")
print()
print()
p = Process(target=task, args=("sub-process",), name="sub-process name")
p.start()
p.join()
if __name__ == "__main__":
sys.exit(main())