python modify process name

Under normal circumstances, we directly start the python program and use ps to view, the displayed result is pyton xxx.py, and web applications use netstat or ss to view and display as python. Too uncharacteristic, too general, very ordinary, and not easy to manage. We can use the third-party library setproctitle to solve this problem.

This time I used top to view the background process and found that some Python processes can't be shut down. If you shut down according to the Python name, it is easy to shut down other software by mistake, so I want to name my own code process and close the process according to my own name.

1. Installation

pip install setproctitle

Or download the source code to install.

Two, use

import setproctitle
setproctitle.setproctitle("进程别名")

Import the module, just set it at the entrance of the program. The entrance of the program can be the import part. Add the above code to the entrance or the import part of the file that starts a new process.

Guess you like

Origin blog.csdn.net/whuzhang16/article/details/110938767