Search code examples
pythonlinuxubuntucommand-linecloud

Command in the Ubuntu's console to check if a code is running


I'm running a Python code in the Ubuntu's console on vast.ai cloud. I don't know if it's been executed or still running. Could you please tell me which command tells it without interrupring the process?

My friend recommends to write sudo ps afux | grep name.py. Also, I've found the following command sudo ps aux | grep name.py | grep -v grepe. These commands do not give any reaction both for my program and for a program that I know is running.


Solution

  • I assume you’ve run the program in one SSH session and are testing whether it’s still running in another session.

    To check that the program is still running, the command you suggest should work (even with the extra “e” at the end). Note that the use of sudo is probably not necessary.

    ps aux | grep name.py | grep -v grep
    

    You can also use the command:

    pgrep -lf name.py
    

    But I suggest that when you connect remotely via SSH, you always use a terminal multiplexer such as Byobu. This way, you can see whether the process you’re interested in is still active, as if you’d just entered the command, since your terminal is in the same state as when you left it.