Python to get pid and process name
1. Install psutil
pip install psutil
If pip doesn't recognize it, go under the downloaded python directory and execute: . .python36\Scripts
2. Access to information codes
import psutil; for proc in psutil.process_iter(): print("pid-%d,name:%s" % (,()))
Python Customizing Process Names
Generally speaking, if we start python program directly and use ps to view it, the result will be pyton, while web applications use netstat or ss to view it as python.
Too impersonal, too generic, very ordinary.
So there are so a group of people, they are not satisfied with the name of the dead, enterprising (curiosity, it may be loaded that), flaunting the personality, so google to a very ( ఠൠఠఠ )ノ the third-party library - setproctitle.
Installation
1. Source code compilation and installation
git clone /dvarrazzo/ cd py-setproctitle python build python install
2. pip install setproctitle
Usage:
#coding:utf8 import setproctitle ("Process alias")
The effect is as follows:
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.