title: How to get current CPU, GPU and RAM usage of a particular program in Python?
body: <p>I have written a python program to detect faces of a video input (webcam) using Haar Cascade. I would like to know how much CPU, GPU and RAM are being utilized by this specific program and not the overall CPU, GPU, RAM usage. </p>
  
  <p>I came across psutil package (<a href="https://pypi.org/project/psutil/" rel="nofollow noreferrer">https://pypi.org/project/psutil/</a>) which enables to profile system resources being used but I could not manage to get system resources being used by a specific program. How can I achieve that?</p>
  
  <p>I have also seen this <a href="https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python">How to get current CPU and RAM usage in Python?</a> but its not what I want.</p>
  
  <p>My python code as follows:</p>
  
  <pre><code>def main():
      #Get current Process ID
      pid = os.getpid()
      #Get resources used by current process
      p = psutil.Process(pid)
      with p.oneshot():
          cpu_percent = p.cpu_percent()
          # Get Memory and GPU usage of this PID as well
  </code></pre>