Why Can't Top Find My Python Processes on Ubuntu?

I am running a Kubuntu (ubuntu), and I executed two command-line apps through the terminal. My user is 'martin'. In the 'top' window, i can't see my python3 processes:

python3 command-line-1
python3 command-line-2

Please see the attach file.

2

1 Answer

See if you can get them using

ps -af | grep python3

Otherwise if the python code uses one of the os.exec*() calls, the same process continues but runs the exec'ed command which is the one you will see in top or ps. You can confirm this like this:

  1. Start the command as a background process and recover its pid

    python3 [whatever}  & echo Python3 started as PID: $!
    
  2. Use ps with the PID you obtained:

    ps -p $pid
    

With some luck you can even catch it "morphing":

#! /bin/bash

python3 {whatever} & pid=$!
for i in {1..10}
do
    ps -p $pid || exit 1
    sleep .2  # adjust for speed
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest