1

My problem: I run a lot of python scripts in background on a remote machine. Some of them need many days. When I type top -U username to check which script ended and which didn't I get a long list looking like that:

54658 user   20   0 7963464   2.9g  13684 R 100.3  0.8   5921:33 python3                                                                          
54982 user   20   0 6243164   1.2g  13696 R 100.3  0.3   5920:46 python3 
98740 user   20   0  737256 508340   5040 S   0.0  0.1  5226:56 python

The problem is that, as you can see, each process id has, as associated command, python (or python3). This makes impossible to understand the correspondence between process id and script. I would really like to have displayed the name of the process there (as it is when running an executable written in C). Is there some way to obtain it?

Please note that:

1) As suggested here I tried making the script an executable itself via chmod +x scriptname and it didn't get any better. I still see python3

2) If I do ps -U username -o pid,cmd as suggested here I get a looooong list of processes and this is not really handy.

It seems weird to me but I have been searching for it and it looks like there is no other question like this, so it shouldn't be a duplicate. If it is, please link me to the answer.

6
  • How are you executing your python scripts? Do your process objects have any access to the cmdline args? Commented Nov 10, 2018 at 1:19
  • 1
    ps -U uname -o pid,cmd|egrep 'progName1|progName2|... ? Good luck. Commented Nov 10, 2018 at 1:28
  • @TheIncorrigible1I execute script via python3 name.py &. They usually don't have access to cmdline argument. Commented Nov 10, 2018 at 1:56
  • @shellter thank you very much. It's not exactly what I am searching for but it still a great improvement. Especially if 'prog1|prog2...' is substituted with *.py Commented Nov 10, 2018 at 1:57
  • 2
    if you add the -c option to your top, as top -c -U username, you should be able to see the command line that you ran to start the script like python3 name.py. Commented Nov 10, 2018 at 2:08

2 Answers 2

4

The top command has numerous options to adjust what it displays. In your case, you probably want to use the -c option to see the actual command line that was used to start your script. So, try top -c -U username.

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

Comments

0

A simple grep would help you

ps -axo pid,cmd | grep [p]ython

You can even filter based on how you run your scripts

ps -axo pid,cmd | egrep '^[0-9]+ python .*'

Note that this only filters the word python from the output of ps.

2 Comments

Do you have a formatting requirement or do you just need to check if the scripts are still running?
Just check is script is running. However @John Andrerson gave the correct answer in a comment to the questione. Thank you in any case, your answer is useful!

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.