title: How to save the memory, pid and process using python
body: <p>How to save the memory, pid and process using python</p>
  
  <pre><code>import psutil    
  tasklist=['firefox']
  out=[]
  for proc in psutil.process_iter():
      if any(task in proc.name() for task in tasklist):
          out.append([{'pid' : proc.pid, 'name' : proc.name()}])
  for o in out[:]:
      print(o)
  name = [j['name'] for i in out for j in i]
  print (name)
  </code></pre>
  
  <p>Retrieve memory usage and Cpu usage</p>
  
  <pre><code>pmap 413 | tail -n 1
  
  total          2987968K
  </code></pre>
  
  <p>413 is firefox pid</p>
  
  <pre><code> ps -p 413 -o %cpu,%mem
  
  %CPU %MEM
   0.1  3.2
  </code></pre>
  
  <p>How to add memory usage and CPU usage to dictionary
  Desired output</p>
  
  <pre><code>[{'pid': 413, 'name': 'firefox','cpu':0.1, 'mem':3.2 }]
  </code></pre>