Operating System - HP-UX
1829783 Members
1709 Online
109992 Solutions
New Discussion

how to check how many files are opened by the process

 
SOLVED
Go to solution
Wojciech
Occasional Contributor

how to check how many files are opened by the process

We are hitting the limit of nfile 12196/12418:
smp1 # sysdef | grep nfile
nfile 12418 - 14- -

smp1 # sar -v | more

HP-UX smp1 B.11.00 U 9000/800 09/06/05

00:00:00 text-sz ov proc-sz ov inod-sz ov file-sz ov
00:01:00 N/A N/A 279/2068 0 1925/2492 0 12196/12418 0

Do you know how check the number of files opened by the particular process , and which process has opened the highest number of files.

Thanks and regards,
W.F.
gunziping large file 1.5G I received the following return: unknown error. What can I do?
9 REPLIES 9
Rajeev  Shukla
Honored Contributor

Re: how to check how many files are opened by the process

use
lsof -p

Cheers
Rajeev
Robert-Jan Goossens
Honored Contributor

Re: how to check how many files are opened by the process

You can use lsof.

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.76/

Best regards,
Robert-Jan
Borislav Perkov
Respected Contributor

Re: how to check how many files are opened by the process

Hi Wojciech,

You can use lsof

#lsof -p

You can find this utility like more others on
http://hpux.connect.org.uk/

Regards,
Borislav
Wojciech
Occasional Contributor

Re: how to check how many files are opened by the process

ok, but does the output of lsof -p reflects 1:1 the output of sar -v file-sz. So if I for instance kill the of the procees which shows me by executing: losof -p |wc -l the 127 result then I by executing of sar -v I should have the file-sz number lessen by 127 accordingly ?
gunziping large file 1.5G I received the following return: unknown error. What can I do?
Borislav Perkov
Respected Contributor

Re: how to check how many files are opened by the process

Be careful you can generate zombies in some cases if you kill the PID.
Robert-Jan Goossens
Honored Contributor

Re: how to check how many files are opened by the process

No this is an output from lsof -p

dbxxx:/# lsof -p 2855 (telnetd)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
telnetd 2855 root cwd VDIR 64,0x3 1024 2 /
telnetd 2855 root txt VREG 64,0x6 94208 16671 /usr (/dev/vg00/lvol6)
telnetd 2855 root mem VREG 64,0x6 20480 2518 /usr/lib/libnss_dns.1
telnetd 2855 root mem VREG 64,0x6 40960 2809 /usr/lib/libnss_files.1
telnetd 2855 root mem VREG 64,0x6 942080 2816 /usr/lib/libsis.sl
telnetd 2855 root mem VREG 64,0x6 24576 2836 /usr/lib/libdld.2
telnetd 2855 root mem VREG 64,0x6 1568768 2814 /usr/lib/libc.2
telnetd 2855 root mem VREG 64,0x6 241664 2711 /usr/lib/dld.sl
telnetd 2855 root mem VREG 64,0x7 532 34952 /var/spool/pwgr/status
telnetd 2855 root 0u inet 0x41e32e68 0t0 TCP dbxxx:telnet->daf00067.intern:1516 (ESTABLISHED)
telnetd 2855 root 1u inet 0x41e32e68 0t0 TCP dbxxx:telnet->daf00067.intern:1516 (ESTABLISHED)
telnetd 2855 root 2u inet 0x41e32e68 0t0 TCP db001:telnet->daf00067.intern:1516 (ESTABLISHED)
telnetd 2855 root 3u VCHR 138,0 0t98 6967 pckt->telm
telnetd 2855 root 4u unix 0x4204a200 0t0 /var/spool/sockets/pwgr/
client2855

Regards,
Robert-Jan
Vibhor Kumar Agarwal
Esteemed Contributor

Re: how to check how many files are opened by the process

lsof is the obvious choice, but if you know a file and want to find out whether any process is using it or not try fuser.
Vibhor Kumar Agarwal
Bill Hassell
Honored Contributor
Solution

Re: how to check how many files are opened by the process

lsof only provides information about a single process. If you want a list of all files opened by all processes, you'll need to run it for every file, but I don't think that's what you want (a listing that is 12,000 lines long). There is no command to list the quantity of files open by each process. Now your current process count is 279 and average processes open 5-10 files each, so the current number of files works out to be about 43 files per process, a very high number.

Therefore, I would suspect that some application program is opening hundreds of files at the same time. To narrow down the choices, sort the processes by memory used:

UNIX95= ps -e -o vsz,pid,ruser,args|sort -rn|head -20

This sorts the processes by memory used. Now run lsof against the largest processes. That may identify the process(es) that use a large number of files. It's also possible that some processes are opening a large nunmber of network sockets. Run the command netstat to see if this is the case.

Now all of this is probably quite normal for the applications. You can set nfile to 50,000 or even 250,000. This is a parameter that makes room for a open files and if your applications need lots of files, this is a very normal task for the system administrator. On the other hand, if you have developers writing programs and they have made errors in coding, then a bad program might needlessly open a large number of files. In that case, you can limit these problem programs using maxfiles and maxfiles_lim. Set maxfiles to about 100 and maxfiles_lim to 2048, then see what programs fail to operate correctly. Then for those programs that are known to be working as designed, use the ulimit -Sn command in the shell to temporarily raise the limit for this one program (or programs).

nproc and nfile can be extremely large if needed, so adjust them as required once possible problem programs have been corrected.


Bill Hassell, sysadmin
Micky_1
Advisor

Re: how to check how many files are opened by the process


for the number of open files for a process consult lsof or glance

to search for processes with lots of open files use the quick&dirty:

lsof | grep " /" | awk '{pl[$2]++} END {for (a in pl) {printf("%d: %d\n", a, pl[a])}}'

this will show the pid and the open files (if the contain a " /".....
(better than nothing ;-))

Micky