0

If I run htop, I see a list of all running processes, and the commands that spawned them.

enter image description here

Is there a way to get the list of running commands from inside Django? I looked at the docs for the OS module, but didn't yet spot a way to do it.

4
  • 1
    What do you mean by "running commands"? The views that are currently running? Commented Nov 20, 2019 at 21:44
  • On the far right of the window, it lists the name of the command, e.g. python3 /my_directory/my_app/manage.py rssrun --settings=server.settings.prod_cnf. I'd like to load this list within my Django app if possible. Commented Nov 20, 2019 at 21:52
  • 1
    Load what list? The list of currently running Django processes? Commented Nov 20, 2019 at 21:56
  • The same list displayed by htop. I've got a cron job that runs regularly. I want it to check this list to see if it's still running from a previous launch and if so, exit immediately. :) Commented Nov 20, 2019 at 22:09

1 Answer 1

2

To get a list of currently running processes you can use ps

result = subprocess.run(['ps aux | grep rssrun'], capture_output=True, shell=True)
print(result.stdout)
Sign up to request clarification or add additional context in comments.

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.