3

I have a set of python scripts which I run as a daemon services. These all work great, but when all the scripts are running and I use top -u <USER>, I see all my scripts running as python.

I would really like to know which script is running under which process id. So is there any way to execute a python script as a different process name?

I'm stuck here, and I'm not ever sure what terms to Google. :-)

Note: I'm using Ubuntu Linux. Not sure if the OS matters or not.

3 Answers 3

1

Try using setproctitle. It should work fine on Linux.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks promising. I'll give it a shot and comment back here.
0

Don't have a linux system here to test this on appropriately, but if the above doesn't work, you should be able to use the same trick they use for things like gzip etc.

The script has to tell what to run it at the top like this:

#!/usr/local/bin/python

Use a softlink like this:

ln -s /usr/local/bin/python ~/bin/myutil

Then just change your script to

#!~/bin/myutil

and it should show up that way instead. You may need to use a hard link instead of a soft link.

Launching a python script using the python script itself (and file associations and/or shell magic) is not very portable, but you can use similar methods on nearly any OS.

Comments

0

The easiest way to get this is using she bang. The first line of your python script should be:

#!/usr/bin/python

or

#!/usr/bin/python3

depending upon whether you use python or python3

and then assign executable permissions to the script as follows:

chmod +x <scriptname>

and then run the script as

./scriptname

this will show up as scriptname in top.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.