Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many open files for each process running for a specific user in Linux

Tags:

linux

lsof

Running Apache and Jboss on Linux, sometimes my server halts unexpectedly saying that the problem was Too Many Open Files.

I know that we might set a higher limit for nproc and nofile at /etc/security/limits.conf to fix the open files problem, but I am trying to get better output, such as using watch to monitor them in real-time.

With this command line I can see how many open files per PID:

lsof -u apache | awk '{print $2}' | sort | uniq -c | sort -n

Output (Column 1 is # of open files for the user apache):

1     PID
1335  13880
1389  13897
1392  13882

If I could just add the watch command it would be enough, but the code below isn't working:

watch lsof -u apache | awk '{print $2}' | sort | uniq -c | sort -n
like image 949
tesla-rules Avatar asked Sep 13 '13 14:09

tesla-rules


1 Answers

You should put the command insides quotes like this:

watch 'lsof -u apache | awk '\''{print $2}'\'' | sort | uniq -c | sort -n'

or you can put the command into a shell script like test.sh and then use watch.

chmod +x test.sh
watch ./test.sh
like image 103
reader_1000 Avatar answered Sep 28 '22 05:09

reader_1000