Jesvin Jose
Jesvin Jose

Reputation: 23098

How do I make python processes run with correct process name?

I have a few long term processes and temporary processes in Python. While shell and C programs run under their own names, all Python processes run as 'python filename.py', which makes it tough to identify processes.

How can I make python processes show up as 'logserver.py' or such in Linux? I use Python 2.7 in Ubuntu 11.10.

Upvotes: 4

Views: 706

Answers (2)

ᅠᅠᅠ
ᅠᅠᅠ

Reputation: 67040

If you want to be explicit, or change the name while the script is running, there's a library for that on PyPI.

 import setproctitle
 setproctitle.setproctitle('logserver')

Making the script executable and starting it directly is often enough, though.

Upvotes: 4

user355252
user355252

Reputation:

Add a shebang to the Python file in question, make the Python file executable (e.g. by chmod a+x ./logserver.py) and start it directly by ./logserver.py.

A shebang is a line telling the kernel which interpreter to use. It's simply a line like #!/usr/bin/env python at the very beginning of the file.

Upvotes: 9

Related Questions