title: How to get the percentage of memory usage of a process?
body: <p>Using the following code, I can get the memory consumption of a give process in MiB:</p>
  
  <pre><code>def memory_usage_psutil():
      # return the memory usage in MB
      import psutil
      process = psutil.Process(os.getpid())
      mem = process.get_memory_info()[0] / float(2 ** 20)
      return mem
  </code></pre>
  
  <p>How can I change this to return the percentage of memory consumption?</p>
  
  <p><strong>Update</strong>: I need to get the current value of <code>%MEM</code> column when executing the <code>top</code> command in terminal for a specific process.</p>
  
  <p><strong>Example</strong>: I need this function to return 14.2 for the process id of VirtualBox process.</p>
  
  <p><img src="https://i.stack.imgur.com/Et3ui.png" alt="enter image description here"></p>