title: how to get all process information in linux?
body: <p>I want to get all process information in a linux server. <br>
  <code>PID, USER, CPU% , COMMAND ...</code><br>
  Exactly, I want to get these information in a python script. I tried <br>
  <code>a,b = commands.getstatusoutput('top -n 1')</code><br>
  This gave me about 20 rows of results ordered by CPU%, but I want more, about 40 or 50 rows of results.<br>
  <br></p>
  
  <h2>How should I do?</h2>
  
  <p>I use psutil as follow, for each proc, it need to wait 1 second. How can I get cpu_percent like top command quickly.<br></p>
  
  <pre><code>for proc in psutil.process_iter():
      try:
          pinfo = proc.as_dict(attrs=['pid', 'username', 'cpu_percent', 'name'])
          pinfo['cpu_percent'] = proc.cpu_percent(interval=1)
          if pinfo['cpu_percent'] &gt; 0:
              print(pinfo)
          except psutil.NoSuchProcess:
              pass
  </code></pre>