title: How many open files for each process running for a specific user in Linux
body: <p>Running Apache and Jboss on Linux, sometimes my server halts unexpectedly saying that the problem was Too Many Open Files.</p>
  
  <p>I know that we might set a higher limit for <em>nproc</em> and <em>nofile</em> at <em>/etc/security/limits.conf</em> to fix the open files problem, but I am trying to get better output, such as using <em>watch</em> to monitor them in real-time.</p>
  
  <p>With this command line I can see how many open files per PID:</p>
  
  <pre><code>lsof -u apache | awk '{print $2}' | sort | uniq -c | sort -n
  </code></pre>
  
  <p>Output (Column 1 is # of open files for the user apache):</p>
  
  <pre><code>1     PID
  1335  13880
  1389  13897
  1392  13882
  </code></pre>
  
  <p>If I could just add the watch command it would be enough, but the code below isn't working:</p>
  
  <pre><code>watch lsof -u apache | awk '{print $2}' | sort | uniq -c | sort -n
  </code></pre>