title: ps: Clean way to only get parent processes?
body: <p>I use <code>ps ef</code> and <code>ps rf</code> a lot.</p>
  
  <p>Here is a sample output for <code>ps rf</code>:</p>
  
  <pre><code>  PID TTY      STAT   TIME COMMAND
   3476 pts/0    S      0:00 su ...
   3477 pts/0    S      0:02  \_ bash
   8062 pts/0    T      1:16      \_ emacs -nw ...
  15733 pts/0    R+     0:00      \_ ps xf
  15237 ?        S      0:00 uwsgi ...
  15293 ?        S      0:00  \_ uwsgi ...
  15294 ?        S      0:00  \_ uwsgi ...
  </code></pre>
  
  <p>And today I needed to retrieve only the <strong>master process</strong> of uwsgi in a script (so I want only 15237 but not 15293 nor 15294).</p>
  
  <p>As of today, I tried some <code>ps rf | grep -v ' \\_ '</code>... but I would like a <strong>cleaner way</strong>.</p>
  
  <p>I also came accross another solution from unix.com's forums:</p>
  
  <pre><code>ps xf | sed '1d' | while read pid tty stat time command ; do [ -n "$(echo $command | egrep '^uwsgi')" ] &amp;&amp; echo $pid ; done
  </code></pre>
  
  <p>But still a <strong>lot of pipes</strong> and <strong>ugly tricks</strong>.</p>
  
  <p>Is there really no <code>ps</code> option or cleaner tricks (maybe using <strong>awk</strong>) to accomplish that?</p>