0

I need to report the number of cores a certain process is using in python (>= v 2.7). Can it be done with some standard python function?

(I cannot use external packages like psutil due to internal restrictions.)

Regards, Paul

  • Does this answer your question? [How to find out the number of CPUs using python](https://stackoverflow.com/questions/1006289/how-to-find-out-the-number-of-cpus-using-python) – Filnor Sep 24 '20 at 09:00
  • multiprocessing.cpu_count() gives the number of CPUs/cores in the system. I need to know how many of those are used by a given process. – Paul Nilsson Sep 24 '20 at 09:03
  • You could call a shell command: https://unix.stackexchange.com/questions/11437/how-to-find-how-many-cores-a-process-is-using `ps -o pid,psr,comm -p ` But I don't know how to obtain that information from pure python. Maybe you could read files in `/proc` – KillPinguin Sep 24 '20 at 09:46
  • I'm doing like this at the moment: cmd = "ps axo pgid,psr | sort | grep %d | uniq | awk '{print $1}' | grep -x %d | wc -l" % (pgrp, pgrp) which is quite horrible so I would prefer a neat python solution. – Paul Nilsson Sep 24 '20 at 12:14

0 Answers0