Frequently Asked Questions about lsof ********************************************************************** | The latest release of lsof is always available via anonymous ftp | | from vic.cc.purdue.edu. Look in pub/lsof.README for its location. | ********************************************************************** ______________________________________________________________________ This file contains frequently asked questions about lsof and answers to them. Vic Abell January 22, 2002 ______________________________________________________________________ Table of Contents: 1.0 General Concepts 1.1 Lsof -- what is it? 1.2 Where do I get lsof? 1.2.1 Are there mirror sites? 1.2.2 Are lsof executables available? 1.2.3 Why can't I get the sum(1) result reported in README.lsof_? 1.3 Where can I get more lsof documentation? 1.4 How do I report an lsof bug? 1.5 Where can I get the lsof FAQ? 1.5.1 How timely is the on-line FAQ? 2.0 Lsof Ports 2.1 What ports exist? 2.2 What about a new port? 2.2.1 User-contributed Ports 2.3 Why isn't there an AT&T SVR4 port? 2.4 Why isn't there an SGI IRIX port? 3.0 Lsof Problems 3.1 Why doesn't lsof report full path names? 3.1.1 Why do lsof -r reports show different path names? 3.1.2 Why does lsof report the wrong path names? 3.1.3 Why doesn't lsof report path names for unlinked (rm'd) files? 3.1.4 Why doesn't lsof report the "correct" hard linked file path name? 3.2 Why is lsof so slow? 3.3 Why doesn't lsof's setgid or setuid permission work? 3.4 Does lsof have security problems? 3.5 Will lsof show remote hosts using files via NFS? 3.6 Why doesn't lsof report locks held on NFS files? 3.6.1 Why does lsof report a one byte lock on byte zero as a full file lock? 3.7 Why does lsof report different values for open files on the same file system (the automounter phenomenon)? 3.8 Why don't lsof and netstat output match? 3.8.1 Why can't lsof find accesses to some TCP and UDP ports? 3.9 Why does lsof update the device cache file? 3.10 Why doesn't lsof report state for UDP socket files? 3.11 I am editing a file with vi; why doesn't lsof find the file? 3.12 Why doesn't lsof report TCP/TPI window and queue sizes for my dialect? 3.13 What does "no more information" in the NAME column mean? 3.14 Why doesn't lsof find a process that ps finds? 3.15 Why doesn't -V report a search failure? 3.16 Portmap problems 3.16.1 Why isn't a name displayed for the portmap registration? 3.16.2 How can I display only portmap registrations? 3.16.3 Why doesn't lsof report portmap registrations for some ports? 3.17 Why is `lsof | wc` bigger than my system's open file limit? 3.18 Why doesn't lsof report file offset (position)? 3.18.1 What does lsof report for size when the file doesn't really have one? 3.19 Problems with path name arguments 3.19.1 How do I ask lsof to search a file system? 3.19.2 Why doesn't lsof find all the open files in a file system? 3.19.3 Why does the lsof exit code report it didn't find open files when some files were listed? 3.19.4 Why won't lsof find all the open files in a directory? 3.19.5 Why are the +D and +d options so slow? 3.19.6 Why do the +D and +d options produce warning messages? 3.20 Why can't my C compiler find the rpcent structure definition? 3.21 Why doesn't lsof report fully on file "foo" on UNIX dialect "bar?" 3.22 Why do I get a complaint when I execute lsof that some library file can't be found? 3.23 Why does lsof complain it can't open files? 3.24 Why does lsof warn "compiled for x ... y; this is z."? 3.25 How can I disable the kernel identity check? 3.26 Why don't ps(1) and lsof agree on the owner of a process? 3.27 Why doesn't lsof find an open socket file whose connection state is past CLOSE_WAIT? 3.28 Why don't machine.h definitions work when the surrounding comments are removed? 3.29 What do "can't read inpcb at 0x...", "no protocol control block", "no PCB, CANTSENDMORE, CANTRCVMORE", etc. mean? 3.30 What do the "unknown file system type" warnings mean? 3.31 Installation 3.31.1 How do I install lsof? 3.31.2 How do I install a common lsof when I have machines that need differently constructed lsof binaries? 3.32 Why do lsof 4.53 and above reject device cache files built by earlier lsof revisions? 3.33 What does "like dev special /dev..." mean in VCHR NAME columns? 3.34 Why does an lsof make fail because of undefined symbols? 3.35 Command Regular Expressions (REs) 3.35.1 What are basic and extended regular expressions? 3.35.2 Why can't I put a slash in a command regular expression? 3.35.3 Why does lsof say my command regular expression wasn't found? 3.36 Why doesn't lsof report on shared memory segments? 3.37 Why does lsof report two instances of itself? 3.38 Why does lsof report '\n' in device cache file error messages? 3.39 Kernel Symbol and Address Problems 3.39.1 What does "lsof: WARNING: name cache hash size length error: 0" mean? 3.39.2 Why does lsof produce "garbage" output? 4.0 AIX Problems 4.1 What is the Stale Segment ID bug and why is -X needed? 4.1.1 Stale Segment ID APAR 4.2 Gcc Work-around for AIX 4.1x 4.3 Gcc and AIX 4.2 4.4 Why won't lsof's Configure allow the use of gcc for AIX below 4.1? 4.5 What is an AIX SMT file type? 4.6 Why does AIX lsof start so slowly? 4.7 Why does exec complain it can't find libc.a[shr.o]? 4.8 What does lsof mean when it says, "TCP no PCB, CANTSENDMORE, CANTRCVMORE" in a socket file's NAME column? 4.9 When the -X option is used on AIX 4.3.3, why does lsof disable it, saying "WARNING: user struct mismatch; -X option disabled?" 4.10 Why doesn't the -X option work on my AIX 5L or 5.1 system? 4.11 Why doesn't /usr/bin/oslevel report the correct AIX version? 4.11.1 Why doesn't /usr/bin/oslevel report the correct AIX version on AIX 5.1? 4.12 Why does lsof for AIX 5.1 Power architecture complain about kernel bit size? 4.13 What can't gcc be used to compile lsof on the ia64 architecture for AIX 5 and above? 4.14 Why does lsof get a segmentation fault when compiled with gcc for a 64 bit Power architecture AIX 5.1 kernel? 5.0 Apple Darwin Problems 5.1 Why does Configure have to check out CVS kernel header files? 5.1.1 Why won't CVS let the Apple Darwin lsof Configure step check out header files? 5.1.2 What CVS branch should I specify for Apple Darwin kernel header file checkout? 5.1.3 How can I supply the missing Apple Darwin kernel header files myself? 5.2 Why doesn't Apple Darwin lsof report text file information? 5.3 Why doesn't Apple Darwin lsof support IPv6? 5.4 Why does lsof complain about a mismatch between the release for which lsof was compiled and the booted Max OS X release? 6.0 BSD/OS BSDI Problems 6.1 Why doesn't lsof report on open kernfs files? 7.0 DEC OSF/1, Digital UNIX, and Tru64 UNIX Problems 7.1 Why does lsof complain about non-existent /dev/fd entries? 7.2 Why does the Digital UNIX V3.2 ld complain about Ots* symbols? 7.3 Why can't lsof locate named pipes (FIFOs) under V3.2? 7.4 Why does lsof use the wrong configuration header files? For example, why can't the lsof compilation find cpus.h? 7.5 Why does lsof indicate incomplete paths with " -- " for Tru64 UNIX 5.1 files? 7.6 Why doesn't lsof report link count, node number, and size for some Tru64 5.x CFS files? 7.7 Why does lsof say it can't read the kernel name list on Digital UNIX 4.x or Tru64 UNIX? 8.0 FreeBSD Problems 8.1 Why doesn't lsof report on open kernfs files? 8.2 Why doesn't lsof work under FreeBSD 4.0? 8.3 Why does Configure abort on FreeBSD 5.0 for lack of devfs.h? 9.0 HP-UX Problems 9.1 What do /dev/kmem-based and PSTAT-based mean? 9.2 /dev/kmem-based HP-UX lsof Questions 9.2.1 Why doesn't a /dev/kmem-based HP-UX lsof compilation use -O? 9.2.2 Why doesn't /dev/kmem-based lsof report HP-UX 10.20 locks correctly? 9.2.3 Why doesn't the /dev/kmem-based CCITT support work under 10.x? 9.2.4 Why can't /dev/kmem-based lsof be compiled with `cc -Aa` or `gcc -ansi` under HP-UX 10.x? 9.2.5 Why does /dev/kmem-based lsof complain about no C compiler? 9.2.6 Why does Configure complain about q4 for /dev/kmem-based lsof for HP-UX 11? 9.2.7 When compiling /dev/kmem-based lsof for HP-UX 11 what do the "aCC runtime: ERROR..." messages mean? 9.2.8 Why doesn't /dev/kmem-based lsof for HP-UX 11 report VxFS file link counts, node numbers, and sizes correctly? 9.2.9 Why can't /dev/kmem-based lsof be built with gcc for 64 bit HP-UX 11? 9.2.9.1 How can I acquire a gcc for building lsof for 64 bit HP-UX 11? 9.3 PSTAT-based HP-UX lsof Questions 9.3.1 Why does PSTAT-based lsof complain about pst_static and other PSTAT structures? 9.3.2 Why does PSTAT-based lsof complain it can't read pst_* structures? 9.3.3 Why does PSTAT-based lsof rebuild the device cache file after each reboot? 9.3.4 Why doesn't PSTAT-based lsof report TCP addresses for telnetd's open socket files? 9.3.5 Why does PSTAT-based lsof cause an HP-UX 11.11 kernel panic? 10.0 Linux Problems 10.1 What do /dev/kmem-based and /proc-based lsof mean? 10.2 /proc-based Linux lsof Questions 10.2.1 Why doesn't /proc-based lsof report file offsets (positions)? 10.2.2 Why does /proc-based lsof report "can't identify protocol" for some socket files? 10.2.3 Why does /proc-based lsof warn about unsupported formats? 10.2.4 Why does /proc-based lsof report "(deleted)" after a path name? 10.2.5 Why doesn't /proc-based lsof report full open file information for all processes? 10.2.6 Why won't Customize offer to change HASDCACHE or WARNDEVACCESS for /proc-based lsof? 10.2.7 Why can't lsof find files on an inaccessible NFS file system? 11.0 NetBSD Problems 11.1 Why doesn't lsof report on open kernfs files? 11.2 Why doesn't lsof report on open files on: file descriptor file systems; /proc file systems; 9660 (CD-ROM) file systems; MS-DOS (floppy disk) file systems; or kernel file systems? 12.0 NEXTSTEP and OPENSTEP Problems 12.1 Why can't lsof report on 3.1 lockf() or fcntl(F_SETLK) locks? 12.2 Why doesn't lsof compile for NEXTSTEP with AFS? 13.0 OpenBSD Problems 13.1 Why doesn't lsof support kernfs on my OpenBSD system? 13.2 Will lsof work on OpenBSD on non-Intel-based architectures? 13.3 problems 13.3.1 Why does the compiler claim nbpg isn't defined? 13.3.2 What value should I assign to nbpg? 13.4 Why doesn't lsof report on open MS-DOS file system (floppy disk) files? 14.0 Output problems 14.1 Why do the lsof column sizes change? 14.2 Why does the offset have ``0t' and ``0x'' prefixes? 14.3 What are the values printed in the FILE_FLAG column and why is 0x sometimes included? 14.3.1 Why doesn't lsof display FILE_FLAG values for my dialect? 14.4 Network Addresses 14.4.1 Why does lsof's -n option cause IPv4 addresses, mapped to IPv6, to be displayed in IPv6 notation? 14.5 Why does lsof output \x, ^x, or \xnn for characters sometimes? 15.0 Pyramid Version Problems 15.0.5 Statement of deprecation 15.1 DC/OSx Problems 15.2 Reliant UNIX Problems 15.2.1 Why does lsof complain that it can't find /stand/unix? 15.2.2 Why does lsof complain about bad kernel addresses? 15.2.3 Why does the Reliant C compiler give so many warning messages when compiling lsof? 15.2.4 Why does the lsof compilation require -Klp64 for Reliant UNIX 5.44 and why does my compiler reject it? 16.0 SCO Problems 16.1 SCO OpenServer Problems 16.1.1 How can I avoid segmentation faults when compiling lsof? 16.1.2 Where is libsocket.a? 16.1.3 Why do I get "warning C4200" messages when I compile lsof? 16.2 SCO UnixWare Problems 16.2.1 Why doesn't lsof compile on my UnixWare 7.1.1 or above system? 16.2.2 Why does lsof complain about node_self() on my UnixWare 7.1.1 or above system? 16.2.3 Why does UnixWare 7.1.1 or above complain about -lcluster, node_self(), or libcluster.so? 16.2.4 Why does UnixWare 7.1.1 or above lsof complain it can't read the kernel name list? 16.2.5 Why doesn't lsof report link count, node number, and size for some UnixWare 7.1.1 or above CFS files? 16.2.6 Why doesn't lsof report open files on all UnixWare 7.1.1 NonStop Cluster (NSC) nodes? 16.2.7 Why doesn't lsof report the UnixWare 7.1.1 NonStop Cluster (NSC) node a process is using? 17.0 Sun Problems 17.0.5 Statement of deprecation 17.1 My Sun gcc-compiled lsof doesn't work -- why? 17.2 How can I make lsof compile with gcc under Solaris 2.[456], 2.5.1, 7, or 8? 17.3 Why does Solaris Sun C complain about system header files? 17.4 Why doesn't lsof work under my Solaris 2.4 system? 17.5 Where are the Solaris header files? 17.6 Where is the Solaris /usr/src/uts//sys/machparam.h? 17.7 Why does Solaris lsof say ``can't read proc table''? 17.8 Why does Solaris lsof complain about a bad cached clone device? 17.9 Why doesn't Solaris make generate .o files? 17.10 Why does lsof report some Solaris 2.3 and 2.4 lock types as `N'? 17.11 Why does lsof Configure say "WARNING: no cc in ..."? 17.12 Solaris 7 and 8 Problems 17.12.1 Why does lsof say the compiler isn't adequate for Solaris 7 or 8? 17.12.2 Why does Solaris 7 or 8 lsof say "FATAL: lsof was compiled for..."? 17.12.3 How do I build lsof for a 64 bit Solaris kernel under a 32 bit Solaris kernel? 17.12.4 How do I install lsof for Solaris 7 or 8? 17.12.5 Why does my Solaris 7 or 8 system say it cannot execute lsof? 17.12.6 How do I build a gcc that will produce 64 bit Solaris 7 and 8 executables? 17.12.7 Why does lsof on my Solaris 7 or 8 system say, "can't read namelist from /dev/ksyms?" 17.13 Solaris and COMMON 17.13.1 What does COMMON mean in the NAME column for a Solaris VCHR file? 17.13.2 Why does a COMMON Solaris VCHR file sometimes seem to have an incorrect minor device number? 17.14 Why don't lsof and Solaris pfiles reports always match? 17.15 Why does lsof say, "kvm_open (namelist=default, core=default): Permission denied?" 17.16 Why is lsof slow on my busy Solaris UFS file system? 17.17 Why is lsof so slow on my Solaris 8 or 9 system? 17.18 Why doesn't lsof support VxFS 3.4 on Solaris 2.6, 7, and 8? 17.18.1 Why does lsof report "vx_inode: vxfsu_get_ioffsets error" for open Solaris 2.6, 7, and 8 VxFS 3.4 files? 17.19 Large file problems 17.19.1 Why does lsof complain it can't stat(2) a Solaris 2.5.1 large file? 17.20 Why does lsof get a segmentation fault on 64 bit Solaris 8 using NIS+? 18.0 Lsof Features 18.1 Why doesn't lsof doesn't report on /proc entries on my system? 18.2 How do I disable the device cache file feature or alter it's behavior? 18.2.1 What's the risk with a perverted device cache file? 18.2.2 How do I put the full host name in a personal device cache file path? 18.2.3 How do I put the personal device cache file in /tmp? 18.3 Why doesn't lsof know about AFS files on my favorite dialect? 18.3.1 Why doesn't lsof report node numbers for all AFS volume files, or how do I reveal dynamic module addresses to lsof? ______________________________________________________________________ 1.0 General Concepts 1.1 Lsof -- what is it? Lsof is a UNIX-specific tool. Its name stands for LiSt Open Files, and it does just that. It lists information about files that are open by the processes running on a UNIX system. See the lsof man page, the 00DIST file, the 00QUICKSTART file, and the 00README file of the lsof distribution for more information. 1.2 Where do I get lsof? Lsof is available via anonymous ftp from vic.cc.purdue.edu. Look in the pub/tools/unix/lsof sub-directory. Compressed and gzip'd tar files with PGP certificates are available. 1.2.1 Are there mirror sites? The lsof distribution is currently mirrored at: ftp://ftp.cerias.purdue.edu/pub/tools/unix/sysutils/lsof ftp://ftp.cert.dfn.de/pub/tools/admin/lsof ftp://ftp.crc.ca/pub/packages/lsof ftp://ftp.cetis.hvu.nl/pub/lsof/ ftp://ftp.fu-berlin.de/pub/unix/tools/lsof ftp://ftp.sunet.se/pub/unix/admin/lsof ftp://ftp.tau.ac.il/pub/unix/admin ftp://ftp.tu-darmstadt.de/pub/sysadmin/lsof ftp://ftp.tux.org/pub/sites/vic.cc.purdue.edu/tools/unix/lsof ftp://ftp.uni-mainz.de/pub/misc/lsof ftp://gd.tuwien.ac.at/utils/admin-tools/lsof ftp://sunsite.ualberta.ca/pub/Mirror/lsof ftp://the.wiretapped.net/pub/security/host-security/lsof/ ftp://wuarchive.wustl.edu/packages/security/lsof http://kaizo.org/mirrors/lsof 1.2.2 Are lsof executables available? Some lsof executables are available in the subdirectory tree pub/tools/unix/lsof/binaries These are neither guaranteed to be current nor cover every dialect and machine architecture. I don't recommend you use pre-compiled lsof binaries; I recommend you obtain the sources and build your own binary. Even if you're a Sun user without a Sun C compiler, you can use gcc to compile lsof. If you must use a binary file, please be conscious of the security and configuration implications in using an executable of unknown or different origin. The lsof binaries are accompanied by PGP certificates. Please use them! Three additional cautions apply to executables: 1. Don't try to use an lsof executable, compiled for one version of a UNIX dialect, on another. Patches can make the dialect version different. 2. If you want to use an lsof binary on multiple systems, they must be running the same dialect OS version and have the same patches. 1.2.3 Why can't I get the sum(1) result reported in README.lsof_? The "Security" section of the README.lsof_ file of the lsof distribution gives md5, sum, and PGP signature information. The simplest, the sum(1) signature, seems to be the trickiest. That's because there are different sum(1) methods, BSD systems usually have cksum(1) instead of sum(1), and different systems compute the block size value differently. First, the lsof sum results are computed with the old, "alternate" algorithm. On newer systems, you can use sum's "-r" option to get that computation result. Second, on BSD systems you usually must use cksum(1) instead of sum(1), because they have no sum(1). To tell cksum(1) to use the old, "alternate" algorithm, use its "-o1" option. Third, the second value that sum reports, the block count, may be computed differently on different systems -- usually block count is considered to be 512 or 1,024. The lsof block counts were computed on a system that considers block size to be 1,024. Solaris 8, for example, considers block size to be 512. If your sum(1) or cksum(1) doesn't report a block count that matches the sum(1) signature given in README.lsof_, check its man page to see what block size it uses, then adjust its block count appropriately. 1.3 Where can I get more lsof documentation? A significant set of documentation may be found in the lsof distribution (See "Where can I get lsof?). There is a manual page, copious documentation in files whose names begin with 00, and a copy of this FAQ in the file 00FAQ (perhaps slightly less recent that this file if you're reading it via a web browser.) Two URLs provide some documentation that appears in the lsof distribution: FAQ: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/FAQ man page: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/lsof_man 1.4 How do I report an lsof bug? If you believe you have discovered a bug in lsof, you can report it via e-mail to . Do NOT report lsof bugs to the UNIX dialect vendor. Before you send me a bug report, please do these things: * Check this file to see if there's a question and answer relevant to your problem. * Make sure you try the latest lsof revision. o Download the latest revision from: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof o While connected to vic.cc.purdue.edu, check for patches: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/patches o If patches exist, install them in the latest revision you just downloaded. Then build the latest revision and see if it fixes your bug. * When you send a bug report, make sure you include output from lsof's -v option. That will tell me what UNIX dialect and lsof revision is involved. 1.5 Where can I get the lsof FAQ? This lsof FAQ is available in the file 00FAQ in the lsof distribution and at the URL: ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/FAQ 1.5.1 How timely is the on-line FAQ? The on-line FAQ is sometimes too timely. :-) I update it as soon as new information is available. That may include information about support that won't appear in the lsof source distribution until the next revision. If you encounter something like that, please send me e-mail at . I may be able to point you at a pre-release distribution that contains the support of interest. 2.0 Lsof Ports 2.1 What ports exist? The pub/lsof.README file carries the latest port information: AIX 4.3.[23], 5L, and 5.1 Apple Darwin 1.[23] and 1.4 for Power Macintosh systems BSDI BSD/OS 4.1 for Intel-based systems DEC OSF/1, Digital UNIX, Tru64 UNIX 4.0, and 5.[01] FreeBSD 4.[2345] and 5.0 for Intel-based systems HP-UX 11.00 and 11.11 Linux 2.1.72 and above for Intel-based systems NetBSD 1.5 for Alpha, Intel, and SPARC-based systems NEXTSTEP 3.[13] OpenBSD 2.[89] and 3.0 for Intel-based systems Caldera OpenUNIX 8 SCO OpenServer Release 5.0.[46] for Intel-based systems SCO UnixWare 7.1.1 for Intel-based systems Solaris 2.6, 7, 8, and 9 BETA-Refresh Lsof version 4 predecessors, versions 3 and 4, may support older version of some dialects. You can find their distributions on vic.cc.purdue.edu in the pub/tools/unix/lsof/OLD subdirectory. 2.2 What about a new port? The 00PORTING file in the distribution gives hints on doing a port. I will consider doing a port in exchange for permanent access to a test host. I require permanent access so I can test new lsof revisions, because I will not offer distributions of dialect ports I cannot upgrade and test. 2.2.1 User-contributed Ports Sometimes I receive contributions of ports of lsof to systems where I can't test future revisions of lsof. Hence, I don't incorporate these contributions into my lsof distribution. However, I do make these contributions available in the directory: pub/tools/unix/lsof/contrib on vic.cc.purdue.edu. Consult the 00INDEX file in the contrib/ directory for a list of the available contributions. 2.3 Why isn't there an AT&T SVR4 port? I haven't produced an AT&T SVR4 port because I haven't seen a UNIX dialect that is strictly limited to the AT&T System V, Release 4 source code. Every one I have seen is a derivative with vendor additions. The vendor additions are significant to lsof because they affect the internal kernel structures with which lsof does business. While some vendor derivatives of SVR4 are similar, each one I have encounted so far has been different enough from its siblings to require special source code. If you're interested in an SVR4 version of lsof, here are some existing ports you might consider: DC/OSx Reliant UNIX SCO UnixWare Solaris 2.4 Why isn't there an SGI IRIX port? Lsof support for IRIX was terminated at lsof revision 4.36, because it had become increasingly difficult for me to obtain information on the IRIX kernel structures lsof needs to access. At IRIX 6.5 I decided the obstacles were too large for me to overcome, and I stopped supporting lsof on IRIX. You'll find the sources for last revision of lsof (4.36) for IRIX via anonymous ftp at vic.cc.purdue.edu in: pub/tools/unix/lsof/OLD/src/lsof_4.36.irix.tar.gz If you wish to pursue the issue, don't contact me, contact SGI. This case was opened with SGI on the subject: Case ID: 0982584 Category: Unix Priority: 30-Moderate Impact Problem Summary: kernel structure header files needed for continued lsof support Problem Description: Email In 07/17/98 19:09:23 3.0 Lsof Problems 3.1 Why doesn't lsof report full path names? Lsof reports the full path name when it is specified as a search argument for open files that match the argument. However, if the argument is a file system mounted-on directory, and lsof finds additional path name components from the kernel name cache, it will report them. Lsof reports path name for file system types that have path name lookup features -- e.g., some versions of AdvFS for Digital and Tru64 UNIX. The Linux /proc-based lsof reports full path names, because the Linux /proc file system provides them. Otherwise, lsof uses the kernel name cache, where it exists and can be accessed, and reports some or all path name components (e.g., the sys and proc.h components of /usr/include/sys/proc.h) for these dialects: Apple Darwin DC/OSx DEC OSF/1, Digital UNIX, Tru64 UNIX FreeBSD HP-UX, /dev/kmem and PSTAT based Linux, /dev/kmem-based NetBSD NEXTSTEP OpenBSD OPENSTEP Reliant UNIX Caldera OpenUNIX SCO OpenServer SCO UnixWare Solaris 2.x, 7, and 8 As far as I can determine, AFS path lookups don't share in kernel name cache operations, so lsof can't identify open AFS path name components. Since the size of the kernel name cache is limited and the cache is in constant flux, it does not always contain the names of all components in an open file's path; sometimes it contains none of them. Lsof reports the file system directory name and whatever components of the file's path it finds in the cache, starting with the last component and working backwards through the directories that contain it. If lsof finds no path components, lsof reports the file system device name instead. When lsof does report some path components in the NAME column, it prefixes them with the file system directory name, followed by " -- ", followed by the components -- e.g., /usr -- sys/path.h for /usr/include/sys/path.h. The " -- " is omitted when lsof finds all the path name components of a file's name. The PSTAT-based HP-UX lsof relies on kernel name cache contents, too, even though its information comes to lsof via pstat() function calls. Consequently, PSTAT-based HP-UX lsof won't always report full paths, but may use the " -- " partial path name notation, or may occasionally report no path name at all but just the file system mounted-on directory and device names. Lsof can't obtain path name components from the kernel name caches of the following dialects: AIX Only the Linux kernel records full path names in the structures it maintains about open files; instead, most kernels convert path names to device and node number doublets and use them for subsequent file references once files have been opened. To convert the device and node number doublet into a complete path name, lsof would have to start at the root node (root directory) of the file system on which the node resides, and search every branch for the node, building possible path names along the way. That would be a time consuming operation and require access to the raw disk device (usually implying setuid-root permission). If the prospect of all that local disk activity doesn't concern you, think about the cost when the device is NFS-mounted. Try using the file system mount point and node number lsof reports as parameters to find -- e.g., $ find -inum -print and you may get an appreciation of what a file system directory tree search would cost. 3.1.1 Why do lsof -r reports show different path names? When you run lsof with its repeat (``-r'') option, you may notice that the extent to which it reports path names for the same files may vary from cycle to cycle. That happens because other processes are making kernel calls affecting the cache and causing entries to be removed from and added to it. 3.1.2 Why does lsof report the wrong path names? Under some circumstances lsof may report an incorrect path name component, especially for files in a rapidly changing directory like /tmp. In a rapidly changing directory, like /tmp, if the kernel doesn't clear the cache entry when it removes a file, a new file may be given the same keys and lead lsof to believe that the old cache entry with the same keys belongs to the new file. Lsof tries to avoid this error by purging duplicate entries from its copy of the kernel name cache when they have the same device and inode number, but different names. This error is less likely to occur in UNIX dialects where the keys to the name cache are node address and possibly a capability ID. The Apple Darwin, BSDI, Digital UNIX, FreeBSD, HP-UX, NEXTSTEP, OPENSTEP, Solaris, Tru64 UNIX, and UnixWare dialects use node address. Apple Darwin, BSDI, FreeBSD, NetBSD, OpenBSD, Tru64 UNIX, and also use a capability ID to further identify name cache entries. 3.1.3 Why doesn't lsof report path names for unlinked (rm'd) files? Lsof never reports a path names for a file that has been unlinked from its parent directory -- e.g., deleted via rm, or the unlink() system call -- even when some process may still hold the file open. That's because the path name is erased from name caches and the parent directory file when the file is unlinked. Unlinked open files are sometimes used by applications for temporary, but invisible storage (i.e., ls won't show them, and no other process can open them.) However, they may occasionally consume disk space to excess and cause concern for a system administrator, who will be unable to locate them with find, ls, du, or other tools that rely on finding files by examining the directory tree. By using lsof's +L option you can see the link count of open files -- in the NLINK column. An unlinked file will have an NLINK value of zero. By using the option +L1 you can tell lsof to display only files whose link count is less than one (i.e., zero). 3.1.4 Why doesn't lsof report the "correct" hard linked file path name? When lsof reports a rightmost path name component for a file with hard links, the component may come from the kernel's name cache. Since the key which connects an open file to the kernel name cache may be the same for each differently named hard link, lsof may report only one name for all open hard-linked files. Sometimes that will be "correct" in the eye of the beholder; sometimes it will not. Remember, the file identification keys significant to the kernel are the device and node numbers, and they're the same for all the hard linked names. 3.2 Why is lsof so slow? Lsof may appear to be slow if network address to host name resolution is slow. This can happen, for example, when the name server is unreachable, or when a Solaris PPP cache daemon is malfunctioning. To see if name lookup is causing lsof to be slow, turn it off with the ``-n'' option. Port service name lookup or portmap registration lookup may also be causes of slow-down. To suppress port service name lookup, specify the ``-P'' option. Lsof doesn't usually make direct portmap calls -- only when +M is specified, or when HASPMAPENABLED is defined during lsof construction. (The lsof help panel, produced with `lsof -h` will display the default portmap registration reporting state.) The quickest first step in checking if lsof is slow because of the portmapper is to use lsof's ``-M'' option. Lsof may be slow if UID to login name lookups are slow. Suppress them with ``-l''. On dialects where lsof uses the kernel name cache, try disabling its use with ``-C''. (You can tell if lsof uses the kernel name cache by looking for ``-C'' in lsof's ``-h'' output.) Of course, disabling kernel name cache use will mean that lsof won't report full or partial path names, just file system and character device names. AIX lsof may be slow to start because of its oslevel identity comparison. See the "Why does AIX lsof start so slowly?" and "Why does lsof warn "compiled for x ... y; this is z.?" sections for more information. 3.3 Why doesn't lsof's setgid or setuid permission work? If you install lsof on an NFS file system that has been mounted with the nosuid option, lsof may not be able to use the setgid or setuid permission you give it, complaining it can't open the kernel memory device -- e.g., /dev/kmem. The only solution is to install lsof on a file system that doesn't inhibit setgid or setuid permission. 3.4 Does lsof have security problems? I don't think so. However, lsof does usually start with setgid permission, and sometimes with setuid-root permission. Any program that has setgid or setuid-root permission, should always be regarded with suspicion. Lsof drops setgid power, holding it only while it opens access to kernel memory devices (e.g., /dev/kmem, /dev/mem, /dev/swap). That allows lsof to bypass the weaker security of access(2) in favor of the stronger checks the kernel makes when it examines the right of the lsof process to open files declared with -k and -m. Lsof also restricts some device cache file naming options when it senses the process has setuid-root power. On a few dialects lsof requires setuid-root permission during its full execution in order to access files in the /proc file system. These dialects include: DC/OSx 1.1 for Pyramid systems Reliant UNIX 5.4[34] for Pyramid systems When lsof runs with setuid-root permission it severely restricts all file accesses it might be asked to make with its options. The device cache file (typically .lsof_hostname in the home directory of the real user ID that executes lsof) has 0600 modes. (The suffix, hostname, is the first component of the host's name returned by gethostname(2).) However, even when lsof runs setuid-root, it makes sure the file's ownerships are changed to that of the real user and group. In addition, lsof checks the file carefully before using it (See the question "How do I disable the device cache file feature or alter it's behavior?" for a description of the checks.); discards the file if it fails the scrutiny; complains about the condition of the file; then rebuilds the file. See the 00DCACHE file of the lsof distribution for more information about device cache file handling and the risks associated with the file. 3.5 Will lsof show remote hosts using files via NFS? No. Remember, lsof displays open files for the processes of the host on which it runs. If the host on which lsof is running is an NFS server, the remote NFS client processes that are accessing files on the server leave no process records on the server for lsof to examine. 3.6 Why doesn't lsof report locks held on NFS files? Generally lock information held by local processes on remote NFS files is not recorded by the UNIX dialect kernel. Hence, lsof can't report it. One exception is some patch levels of Solaris 2.3, and all versions of Solaris 2.4 and above. Lsof for those dialects does report on locks held by local processes on remotely mounted NFS files. 3.6.1 Why does lsof report a one byte lock on byte zero as a full file lock? When a process has a lock of length one, starting at byte zero, lsof can't distinguish it from a full file lock. That's because most UNIX dialects represent both locks the same way in their file lock (flock or eflock) structures. 3.7 Why does lsof report different values for open files on the same file system (the automounter phenomenon)? On UNIX dialects where file systems may be mounted by an automounter with the ``direct'' type, lsof may sometimes report difference DEVICE, SIZE/OFF, INODE and NAME values when asked to report files open on the file system. This happens because some files open on the file system -- e.g., the current directory of a shell that changed its directory to the file system as the file system's first reference -- may be characterized in the kernel with temporary automounter node information. The cd doesn't cause the file system to be mounted. A subsequent reference to the file system -- e.g., an ls of any place in it -- will cause the file system to be mounted. Processes with files open to the mounted file system are characterized in the kernel with data that reflects the mounted file system's parameters. Unfortunately some kernels (e.g., some versions of Solaris 2.x) don't revisit the process that did only a change-directory for the purpose of updating the data associated with the open directory file. The file continues to be characterized with temporary automounter information until it does another directory change, even a trivial ``cd .''. Lsof will report on both reference types, when supplied the file system name as an argument, but the data lsof reports will reflect what it finds in the kernel. For the different types lsof will display different data, including different major and minor device numbers in the DEVICE column, different lengths in the SIZE/OFF column, different node numbers in the INODE column, and slightly different file system names in the NAME column. In contrast, fuser, where available, can only report on one reference type when supplied the file system name as an argument. Usually it will report on the one that is associated with the mounted file system information. If the only reference type is the temporary automounter one, fuser will often be silent about it. 3.8 Why don't lsof and netstat output match? Lsof and netstat output don't match because lsof reports the network information it finds in open file system objects -- e.g., socket files -- while netstat often gets its information from separate kernel tables. The information available to netstat may describe network activities never or no longer associated with open files, but necessary for proper network state machine operation. For example, a TCP connection in the FIN_WAIT_[12] state may no longer have an associated open file, because the connection has been closed at the application layer and is now being closed at the TCP/IP protocol layer. 3.8.1 Why can't lsof find accesses to some TCP and UDP ports? Kernel implementations sometimes set aside TCP and UDP ports for communicating with support activities running in application layer servers -- the automountd and amd daemons, and the NFS biod and nfsd daemons are examples. Netstat may report the ports are in use, but lsof doesn't. These kernel ports are not associated with file system objects, may be set aside by the kernel on demand, and sometimes are never released. Because they aren't associated with open file system objects, they are transparent to lsof. After all, lsof does stand for LiSt Open Files, and there are no open files associated with these kernel ports. I don't know a way to determine when ports reported by netstat but not by lsof are reserved by the kernel. 3.9 Why does lsof update the device cache file? At the end of the lsof output you may see the message: lsof: WARNING: /Homes/abe/.lsof_vic was updated. In this message /Homes/abe/.lsof_vic is the path to the private device cache file for login abe. (See 00DCACHE.) Lsof issues this message when it finds it necessary to recheck the system device directory (e.g., /dev or /devices) and rebuild the device cache file during the open file scan. Lsof may need to do these things it finds that a device directory node has changed, or if it cannot find a device in the cache. 3.10 Why doesn't lsof report state for UDP socket files? Lsof reports UDP TPI connection state -- TS_IDLE, TS_BOUND, etc. -- for a limited set of dialects, including DC/OSx, Reliant UNIX, Solaris 2.x, 7, 8, and 9 BETA-Refresh. TPI state is stream-based TCP/IP information that isn't available in many dialects. The general rule is if netstat(1) reports TPI state, lsof will too. 3.11 I am editing a file with vi; why doesn't lsof find the file? Vi doesn't have the file open. It opens the file, makes a temporary copy (usually in /tmp or /usr/tmp), and does its work in that file. When you update the file from vi, it reopens and rewrites the file. During the vi session itself, except for the brief periods when vi is reading or rewriting the file, lsof can't find an open reference to the file from the vi process, because there is none. 3.12 Why doesn't lsof report TCP/TPI window and queue sizes for my dialect? Lsof only reports TCP/TPI window sizes for Solaris, because only its netstat reports them. The intent of providing TCP/TPI information in lsof NAME column output is to make it easier to match netstat output to lsof output. In general lsof only reports queue sizes for both TCP and UDP (TPI) connections on BSD-derived UNIX dialects, where both sets of values appear in kernel socket queue structures. SYSV-derived UNIX dialects whose TCP/IP implementations are based on streams generally provide only TCP queue sizes, not UDP (TPI) ones. While you may find that netstat on some SYSV-derived UNIX dialects with streams TCP/IP may report UDP (TPI) queue sizes, you will probably also find that the sizes are always zero -- netstat supplies a constant zero for UDP (TPI) queue sizes to make its headers align the same for TCP and UDP (TPI) connections. Solaris seems to get it right -- i.e., its netstat does not report UDP (TPI) queue sizes. When in doubt, I chose to avoid reporting UDP (TPI) queue sizes for UNIX dialects whose netstat-reported values I knew to be a constant zero or whose origin I couldn't determine. OSR is a dialect in this category. 3.13 What does "no more information" in the NAME column mean? When lsof can find no successor structures -- a gnode, inode, socket, or vnode -- connected to the file structure of an open descriptor of a process, it reports "no more information" in the NAME column. The TYPE, DEVICE, SIZE/OFF, and INODE columns will be blank. Because the file structure is supposed to contain a pointer to the next structure of a file's processing support, if the pointer is NUL, lsof can go no further. Some UNIX dialects have file structures for system processes -- e.g., the sched process -- that have no successor structure pointers. The "no more information" NAME will commonly appear for these processes in lsof output. It may also be the case that lsof has read the file structure while it is being assembled and before a successor structure pointer value has been set. The "no more information" NAME will again result. Unless lsof output is filled with "no more information" NAME column messages, the appearance of a few should be no cause for alarm. 3.14 Why doesn't lsof find a process that ps finds? If lsof fails to display open files for a process that ps indicates exists, there may be several reasons for the difference. The process may be a "zombie" for which ps displays the "(defunct)" state. In that case, the process has exited and has no open file information lsof can display. It does still have a process structure, sufficient for the needs of ps. Another possible explanation is that kernel tables and structures may have been changing when lsof looked for the process, making lsof unable to find all relevant process structures. Try repeating the lsof request. 3.15 Why doesn't -V report a search failure? The usual reason that -V won't report a search failure is that lsof located the search item, but was prevented from listing it by an option that doesn't participate in search failure reporting. For example, this lsof invocation: $ lsof -V -i TCP@foobar -a -d 999 may not report that it can't find the Internet address TCP@foobar, even if there is an open file connected to that address, unless the open file also has a file descriptor number of 999 (the ``-a -d 999'' options). 3.16 Portmap problems 3.16.1 Why isn't a name displayed for the portmap registration? When portmap registration reporting is enabled, any time there is a registration for a local TCP or UDP port, lsof displays it in square brackets, following the port number or service name -- e.g., ``:1234[name]'' or ``:name[100083]''. The TCP or UDP port number or service number (what follows the `:') is displayed under the control of the lsof -P option. The registration identity is held by the portmapper and may be a name or a number, depending on how the registration's owner declared it. Lsof reports what the port map holds and cannot derive a registration name from a registration number. Lsof can be compiled with registration reporting enabled or disabled by default, under the control of the HASPMAPENABLED #define (usually in machine.h). The lsof help panel (`lsof -h`) will show the default. Lsof is distributed with reporting disabled by default. 3.16.2 How can I display only portmap registrations? Lsof doesn't have an option that will display only TCP or UDP ports with portmap registrations. The +M option only enables the reporting of registration information when Internet socket files are displayed; +M doesn't select the displaying of Internet socket files -- the -i option does that. This simple lsof pipe to grep will do the job: $ lsof -i +M | grep "\[" This works because -i selects Internet socket files, +M enables portmap registration reporting, and only output lines with opening square brackets will have registrations. When portmap registration reporting is enabled by default, because the lsof builder constructed it that way, +M is not necessary. (The lsof help panel, produced with `lsof -h` will display the default portmapper registration reporting state.) However, specifying +M when reporting is already enabled is acceptable, as is specifying -M when reporting is already disabled. Digression: lsof will accept `+' or `-' as a prefix to most options. (That isn't documented in the man page or help panel to reduce confusion and complexity.) The -i option is as acceptable as +i, so the above example could be written a little more tersely as: $ lsof +Mi | grep "\[" But be careful to use the ``Mi'' ordering, since ``iM'' implies M is an address argument to `i'. 3.16.3 Why doesn't lsof report portmap registrations for some ports? Lsof reports portmap registrations for local TCP and UDP ports only. It identifies local ports this way: * The port appears in the local address section of the kernel structure that contains it. * The port appears in the foreign address section of a kernel structure whose local and foreign Internet addresses are the same. * The port appears in the foreign address section of a kernel address structure whose Internet address is INADDR_LOOPBACK (127.0.0.1). Following these rules, lsof ignores foreign portmapped ports. That's done for reasons of efficiency and possible security prohibitions. Contacting all remote portmappers could take a long time and be blocked by network difficulties (i.e., be inefficient). Many firewalls block portmapper access for security reasons. Lsof may occasionally ignore portmap registration information for a legitimate local port by virtue of its local port rules. This can happen when a port appears in the foreign part of its kernel structure and the local and foreign Internet addresses don't match (perhaps because they're on different interfaces), and the foreign Internet address isn't INADDR_LOOPBACK (127.0.0.1). 3.17 Why is `lsof | wc` bigger than my system's open file limit? There is a strong temptation to count open files by piping lsof output to wc. If your purpose is to compare the number you get to some Unix system parameter that defines the number of open files your system can have, resist the temptation. One reason is that lsof reports a number of "files" that don't occupy Unix file table space -- current working directories, root directories, jail directories, text files, library files, memory mapped files are some. Another reason is that lsof can report a file shared by more than one process that itself occupies only one file table slot. If you want to know the number of open files that occupy file table slots, use the +ff option and process the lsof output's FILE_ADDR column information with standard Unix tools like cut, grep, sed, and sort. You might also consider using use lsof's field output with +ff, selecting the file struct address with -FF, and processing the output with an AWK or Perl script. See the list_fields.awk and list_fields.perl scripts in the scripts/ subdirectory of the lsof distribution for hints on file struct post-processing filters. 3.18 Why doesn't lsof report file offset (position)? Lsof won't report a file offset (position) value if the -s option has been specified, or if the dialect doesn't support the displaying of file offset (position). That lsof is reporting only file size is indicated by the fact that the appropriate column header says SIZE instead of SIZE/OFF. If lsof doesn't support the displaying of file offset (position) -- e.g., for Linux /proc-based lsof -- the -h or -? output panel won't list the -o option. Sometimes the availability of file offset information depends on the dialect's kernel. This is particularly true for socket file offsets. Maintenance of offsets for pseudo-terminal devices varies by UNIX dialect and is related to how the dialect kernel implements pseudo-terminal support. Kernels like AIX, for example, that short-circuit the transfer of data between socket and pseudo devices to reduce TCP/IP daemon interrupt rates won't advance offsets in the TCP/IP daemon socket files. Instead they will advance offsets in the open standard I/O files of the shell child precess where the pseudo-terminal devices are used. When in doubt about the behavior of lsof in reporting file offset information, do some carefully measured experiments, consult the lsof sources, or contact me at to discuss the matter. 3.18.1 What does lsof report for size when the file doesn't really have one? When a file has no true size -- e.g., it's a socket, a FIFO, or a pipe -- lsof tries to report the information it finds in the kernel that describes the contents of associated kernel buffers. Thus, for example, size for most TCP/IP files is socket buffer size. The size of the socket read buffer is reported for read-only files; the size of the write buffer for write-only files; and the sum of the buffers sizes for read-write files. 3.19 Problems with path name arguments 3.19.1 How do I ask lsof to search a file system? You can ask lsof to search for all open files on a file system by specifying its mounted path name as an lsof argument -- e.g., $ lsof / Output of the mount command will show file system mounted path names. It will also show the mounted-on device path for the file system. If the mounted-on device is a block device (the permission field in output of `ls -l ` starts with a `b/), you can specify it's name, too -- e.g., $ lsof /dev/sd0a If the mounted-on device isn't a block device -- for example, some UNIX dialects call a CD-ROM device a character device (ls output starts with a `c') -- you can force lsof to assume that the specified device names a file system with the +f option -- e.g., $ lsof +f -- /dev/sd0a (Note: you must use ``--'' after +f or -f if a file name follows immediately, because +f and -f can be followed by characters that specify flag output selections.) When you use +f and lsof can't match the device to a file system, lsof will issue a complaint. The +f option may be used in some dialects to ask lsof to search for an NFS file system by its server name and server mount point. If the mount application reports an NFS file system mounted-on value that way, then this sample lsof request should work. $ lsof +f -- fleet:/home/fleet/u5 Finally, you can use -f if you don't want a mounted file system path name to be considered a request to report all open files on the file system. This is useful when you want to know if anyone is using the file system's mounted path name. This example directs lsof to report on open access to the `/' directory, including when it's being used as a current working or root directory. $ lsof -f -- / The lsof -f option performs the same function as -f does in some fuser implementations. However, since the lsof -c option was chosen for another purpose before the `f' option was added to lsof, +f was selected as the analogue to the fuser -c option. (Sorry for the potential confusion.) 3.19.2 Why doesn't lsof find all the open files in a file system? Lsof may not find all the open files in a file system for several reasons. First, some processes with files open on the file system may have been changing status when lsof examined the process table, and lsof "missed" them. Remember, the kernel changes much faster than lsof can respond to the changes. Second, be sure you have specified the file system correctly. Perhaps you specified a file instead. You can use lsof's -V option to have lsof report in detail on what it couldn't find. Make sure the report for the file system you specified says "file system." Here's some -V output: $ /lsof -V /tmp ./lsof.h ./lsof COMMAND PID USER FD TYPE DEVICE SIZE/OFF INODE NAME lsof 2688 abe txt VREG 18,1,7 1428583 226641 ./lsof lsof 2689 abe txt VREG 18,1,7 1428583 226641 ./lsof lsof: no file use located: ./lsof.h You can also use lsof's +f option to force it to consider a path name as a file system. If lsof can't find a file system by the specified name, it will issue a complaint -- e.g., $ lsof +f -- /usr lsof: not a file system: /usr (/usr is a directory in the / file system.) 3.19.3 Why does the lsof exit code report it didn't find open files when some files were listed? Sometimes lsof will list some open files, yet return a non-zero exit code, suggesting it hasn't found all the specified files. The first thing you should when you suspect lsof is incorrect is to repeat the request, adding the -V option. In the resulting report you may find that your file system specification really wasn't a file system specification, just a file specification. Finally, if you specify two files or two file systems twice, lsof will credit all matches to the first of the two and believe that there were no matches for the second. It's possible to specify a single file system twice with different path names by using both its mounted directory path name and mounted-one device name. $ lsof +f -V spcuna:/sysprog /sysprog COMMAND PID USER FD TYPE DEVICE SIZE/OFF INODE NAME ksh 11092 abe cwd VDIR 39,0,1 1536 226562 /sysprog (spcuna:/sysprog) ... lsof: no file system use located: spcuna:/sysprog All matches were credited to /sysprog; none to spcuna:/sysprog. 3.19.4 Why won't lsof find all the open files in a directory? When you give lsof a simple directory path name argument (not a file system mounted-on name), you are asking it to search for processes that have the directory open as a file, or as a process-specific directory -- e.g., root or current working directory. If you want to list instances of open files inside the directory, you need to specify the individual path names of those files, or use the lsof +D and +d options. See the answer to the question "Why are the +D and +d options so slow?" before you use +D or +d casually. See the answer to the question "Why do the +D and +d options produce warning messages?" for an explanation of some process authority limitations of +D and +d. 3.19.5 Why are the +D and +d options so slow? The +D and +d options cause lsof to build a path name search list for a specified directory. +D causes lsof to descend the directory to its furthest subdirectory, while +d restricts it to the top level. In both cases, the specified directory itself is included in the search list. In both symbolic links are ignored. Building such a search list can take considerable time, especially when the specified directory contains many files and subdirectories -- lsof must call the system readlink() and stat() functions for each file and directory. Storing the search list can cause lsof to use more than its normal amount of dynamic memory -- each file recorded in the search list consumes dynamic memory for its path name, characteristics, and search linkages. Using the list means lsof must search it for every open file in the system. Building the search list for a directory specified on some file systems can be slow -- e.g., for an NFS directory with many files. Some file systems have special logging features that can introduce additional delays to the building of the search list -- e.g., NFS logging, or logging on a Solaris UFS file system. The bottom line is that slow search list construction may not be so much an lsof problem as a file system problem. (Hint: if you're using Solaris UFS logging, consider specifying the "logging,noatime" option pair to reduce the number of atime writes to the UFS logging queue and disk.) A somewhat risky way to speed up lsof's building of the search list is to use lsof's ``-O'' option. It forces lsof to do all system calls needed to build the search list directly, rather than in a child process. While direct system calls are much faster, they can block in the kernel -- e.g., when an NFS server stops responding -- stopping lsof until the kernel operation unblocks. As an example of the load +D can impose, consider that an `lsof +D /` on a lightly loaded NeXT '040 cube with a 1GB root file system disk took 4+ minutes of real time. It also generated several hundred error messages about files and directories the lsof process didn't have permission to access with stat(2). The bottom line is that +D and +d should be used cautiously. +D is more costly than +d for deeply nested directory trees, because of the full directory descent it causes. So use +d where possible. And you might need to consider the performance of the file system that holds the directory you name with +d or +D. In view of these warnings, when is it appropriate to use +D or +d? Probably the most appropriate time is when you would specify the directory's contents to lsof with a shell globbing construct -- e.g., `lsof *`. If that's what you need to do, `lsof +d .` is probably more efficient than having the shell produce a directory list, form it into an argument vector, and pass the vector to lsof for it to unravel. See the answer to the question "Why do the +D and +d options produce warning messages?" for an explanation of some process authority limitations of +D and +d. 3.19.6 Why do the +D and +d options produce warning messages? +D and +d option processing is limited by the authority of the lsof process -- i.e., lsof can only examine (with lstat(2) and stat(2)) files the owner of the process can access. If the ownership, group membership, or permissions of the specified directory, file within it, or directory within it prevents the owner of the lsof process from using lstat(2) or stat(2) on it, lsof will issue a warning message, naming the path and giving the system's (lstat(2's or stat(2)'s) reason (errno explanation text) for refusing access. As an example, assume user abc has a subdirectory in /tmp, owned by abc and readable, writable and searchable by only its owner. If user def asks lsof to search for all /tmp references with +D or +d, lsof will be unable to lstat(2) or stat(2) anything in abc's private subdirectory, and will issue an appropriate warning. Lsof warnings can usually be suppressed with the -w option. However, using -w with +D or +d means that there will be no indication why lsof couldn't find an open reference to a restricted directory or something contained in it. Hint: if you need to use +D or +d and avoid authority warnings, and if you have super-user power, su and use lsof with +D or +d as root. 3.20 Why can't my C compiler find the rpcent structure definition? When you try to compile lsof your compiler may complain that the rpcent structure is undefined. The complaints may look like this: >print.c: In function `fill_portmap': >print.c:213: dereferencing pointer to incomplete type >... The most likely cause is that someone has allowed a BIND installation to update /usr/include/netdb.h (or perhaps /usr/include/rpc/netdb.h), removing the rpcent structure definition that lsof expects to find there. Only Solaris has an automatic work-around. (See dlsof.h in dialects/sun.). The Solaris work-around succeeds because there is another header file, , with the rpcent structure definition, and there is a Solaris C pre-processor test that can tell when the BIND is in place and hence must be included. Doubtlessly there are similar work-arounds possible in other UNIX dialects whose header files have been "touched" by BIND, but in general I recommend restoration of the vendor's and any other header files BIND might have replaced. (I think BIND replaces , , -- and maybe others.) 3.21 Why doesn't lsof report fully on file "foo" on UNIX dialect "bar?" Lsof sometimes won't report much information on a given file, or may even report an error message in its NAME column. That's usually because the file is of a special type -- e.g., in a file system specific to the UNIX dialect -- and I haven't used a system where the file appeared during my testing. If you encounter such a situation, send me e-mail at and we may be able to devise an addition to lsof that will report on the file in question. 3.22 Why do I get a complaint when I execute lsof that some library file can't be found? On systems where the LIBPATH (or the equivalent) environment variable is used to record the library search path in executable files when they are built, an incorrect value may make it impossible for the system to find the shared libraries needed to load lsof for execution. This may be particularly true on systems like AIX >= 4.1.4, where the lsof Makefile takes the precautionary step of using the -bnolibpath loader flag to insure that the path to the private static lsof library is not recorded in the lsof binary. Should LIBPATH be invalid when lsof is built, it will be recorded in the lsof binary as the default library path search order and lead to an inability to find libraries when lsof is executed. So, if you get missing library complaints when you try to execute lsof, check LIBPATH, or whatever environment variable is used on your system to define library search order in executable files. Use the tools at your disposal to look at the library paths recorded in the lsof binary -- e.g., chatr on HP-UX, dump on AIX, ldd on Solaris. Make sure, too, that when the correct library search path has been recorded in the executable file, the required library files exist at one or more of the search paths. 3.23 Why does lsof complain it can't open files? When lsof begins execution, unless it has been asked to report only help or version information, typically it will attempt to access kernel memory and symbol files -- e.g., /unix, /dev/kmem. Even though lsof needs only permission to open these files for reading, read access to them might be restricted by ownerships and permission modes. So the first step to diagnosing lsof problems with opening files is to use ls(1) to examine the ownerships and permission modes of the files that lsof wants to open. You may find that lsof needs to be installed with some type of special ownership or permission modes to enable it to open the necessary files for reading. See the Installing Lsof section of 00README for more information. 3.24 Why does lsof warn "compiled for x ... y; this is z."? Unless warnings are suppressed (with -w) or the kernel identity check symbol (HASKERNIDCK) definition has been deleted, all but one lsof dialect version (exception: /proc-based Linux lsof) compare the identity of the running kernel to that of the one for which lsof was constructed. If the identities don't match, lsof issues a warning like this: lsof: WARNING: compiled for Solaris release 5.7; this is 5.6. Two kernel identity differences can generate this warning -- the version number and the release number. Build and running identity differences are usually significant, because they usually indicate kernels whose structures are different -- kernel structures commonly change at dialect version releases. Since lsof reads data from the kernel in the form of structures, it is sensitive to changes in them. The general rule is that an lsof compiled for one UNIX dialect version will not work correctly when run on a different version. There are three work-arounds: 1) use -w to suppress the warning -- and risk missing other warnings; 2) permanently disable the identity check by deleting the definition of HASKERNIDCK in the dialect's machine.h header file -- with the same risk; or 3) rebuild lsof on the system where it is to be run. (Deleting HASKERNIDCK can be done with the Customize script or by editing machine.h.) Generally checking kernel identity is a quick operation for lsof. However, it is potentially slow under AIX, where lsof must run /usr/bin/oslevel. To speed up lsof, use -w to suppress the /usr/bin/oslevel test. See "Why does AIX lsof start so slowly?" for more information. 3.25 How can I disable the kernel identity check? The kernel identity check is controlled by the HASKERNIDCK definition. When it is defined, most dialects (exclusion: /proc-based Linux lsof) will compare the build-time kernel identity with the run-time one. To disable the kernel identity check, disable the HASKERNIDCK definition in the dialect's machine.h header file. The Customize script can be used to do that in its section about the kernel identity check. Caution: while disabling the kernel identity check may result in smaller lsof startup overhead, it comes with the risk of executing an lsof that may produce warning messages, error messages, incorrect output, or no output at all. 3.26 Why don't ps(1) and lsof agree on the owner of a process? Generally the user ID lsof reports in its USER column is the process effective user ID, as found in the process structure. Sometimes that may not agree with what ps(1) reports for the same process. There are sundry reasons for the difference. Sometimes ps(1) uses a different source for process information, e.g., the /proc file system or the psinfo structure. Sometimes the kernel is lax or confused (e.g., Solaris 2.5.1) about what ID to report as the effective user ID. Sometimes the system carries only one user ID in its process structure (some BSD derivatives), leaving lsof no choice. The differences between lsof and ps(1) user identifications should be small and normally it will be apparent that the confusion is over a process whose application has changed to an effective user ID different from the real one. 3.27 Why doesn't lsof find an open socket file whose connection state is past CLOSE_WAIT? TCP/IP connections in states past CLOSE_WAIT -- e.g., FIN_WAIT_1, CLOSING, LAST_ACK, FIN_WAIT_2, and TIME_WAIT -- don't always have open files associated with them. When they don't, lsof can't identify them. When the connection state advances from CLOSE_WAIT, sometimes the open file associated with the connection is deleted. 3.28 Why don't machine.h definitions work when the surrounding comments are removed? The machine.h header files in dialect subdirectories have some commented-out definitions like: /* #define HASSYSDC "/your/choice/of/path */ You can't simply remove the comments and expect the definition to work. That's intended to make you think about what value you are assigning to the symbol. The assigned value might have a system-specific convention. HASSYSDC, for example, might be /var/db/lsof.dc for FreeBSD, but it might be /var/adm/lsof.dc for Solaris. Symbols defined in the lsof documentation are described in 00PORTING, other machine.h comments, and other lsof documentation files. HASSYSDC, for example, is discussed in 00DCACHE. When comments and documentation don't suffice, consult the source code for hints on how the symbol is used. 3.29 What do "can't read inpcb at 0x...", "no protocol control block", "no PCB, CANTSENDMORE, CANTRCVMORE", etc. mean? Sometimes lsof will report "can't read inpcb at 0x00000000", "no protocol control block", "no PCB, CANTSENDMORE, CANTRCVMORE" or a similar message in the NAME column for open TCP socket files. These messages mean the file's socket structure lacks a pointer to the INternet Protocol Control Block (inpcb) where lsof expects to find connection addresses -- local and foreign ports, local and foreign IP addresses. The socket file has probably been submitted to the shutdown(2) function for processing. In some implementations lsof issues the "no PCB, CANTSENDMORE, CANTRCVMORE" message, which tries to explain the absence of a protocol control block by showing the socket state settings that have been made by the shutdown(2) function. If a non-zero address follows the "0x" in the "can't read inpcb" message, it means lsof couldn't read inpcb contents from the indicated address in kernel memory. 3.30 What do the "unknown file system type" warnings mean? Lsof may report a message similar to" unknown file system type, v_op: 0x10472f10 in the NAME column for some files. This means that lsof has encountered a vnode for the file whose operation switch address (from v_op) references a file system type for which there is no support in lsof. After lsof identifies the file system type, it uses pre-compiled code to locate the file system specific node for the file where lsof finds information like file size, device number, node number, etc. To get some idea of what the file system type might be, use nm on your kernel symbol file to locate the symbol name that corresponds to the v_op address -- e.g., on Solaris do: $ nm -x /dev/ksyms | grep 0x10472f10 0x10472f10 ... |file_system_name_vnodeops Where "file_system_name" is the clue to the unsupported file system. Lsof doesn't use the v_op address to identify file system types on all dialects. Sometimes it uses an index number it finds in the vnode. It will translate that symbol to a short name in the warning message -- e.g., "nfs3" -- if possible. 3.28 Installation 3.31.1 How do I install lsof? There is no "standard" way to install lsof. Too much depends on local conditions for me to be able to provide working install rules in the lsof make files. (The skeleton install rules you will find just give "hints.") See the "Installing Lsof" section of 00README for a fuller explanation. To install lsof you will need to consider these questions: * Who should be able to use lsof? (See HASSECURITY in the "Security" section of 00README.) * Where should lsof be installed? This is a decision mostly dictated by local conditions. Somewhere in /usr/local -- etc/ or sbin/ -- is a common choice. * What permissions should I give the lsof executable? The answer to this varies by dialect. The make files have install rules that give hints. The "Installing Lsof" section of 00README gives information, too. * What if I want to install lsof in a shared file system for machines that require different lsof configurations? See the next question and answer, "How do I install a common lsof when I have machines that need differently constructed lsof binaries?" 3.31.2 How do I install a common lsof when I have machines that need differently constructed lsof binaries? A dilemma that faces some system administrators when they install lsof in a shared file system -- e.g., NFS -- is that they must have different lsof executables for different systems. The answer is to build an lsof wrapper script that is executed in place of lsof. The script can use system commands to determine which lsof binary should be executed. Consider this example. You have HP-UX machines with 32 and 64 bit kernels that share the /usr/local/sbin directory where you want to install lsof. Consequently, on each system you must use a different lsof executable, built for the system's bit size. (That's because lsof reads kernel structures, sized by the kernel's bit size.) One answer is to install three things in /usr/local/sbin: 1) a 32 bit lsof as lsof32; 2) a 64 bit lsof as lsof64; and 3) an lsof script. The script might look like this one, based on work by Amir J. Katz : #!/bin/sh x=`/usr/bin/getconf KERNEL_BITS` # returns 32 or 64 if /usr/bin/test "X$x" = "X32" then lsof32 $* else if /usr/bin/test "X$x" = "X64" then lsof64 $* else echo "Can't determine which lsof executable to use;" echo "getconf KERNEL_BITS says: $x" exit 1 fi fi Solaris users should consult "How do I install lsof for Solaris 7 or 8?" for information on a similar trick using the Solaris isaexec command. Users of other dialects might be able to use a command like uname(1) that can identify a distinguishing feature of the system to be incorporated in pre-installed lsof executable names. For example, use `uname -r` and install binaries with suffixes that match `uname -r` output. 3.32 Why do lsof 4.53 and above reject device cache files built by earlier lsof revisions? When lsof revisions 4.53 run and encounter a device cache file built by an earlier revision, it will reject the file and build a new one. The rejection will be advertised with these messages: lsof: WARNING: no /dev device in : 2 sections ... lsof: WARNING: created device cache file: This happens because the header line of the device cache file was changed at revision 4.53 to contain the number of the device on which the device directory resides. The old device cache file header line -- the "2 sections" line in the above warning message, node reads "2 sections, dev=600". This is not a serious problem, since lsof automatically rebuilds the device cache file with the correct header line. 3.33 What does "like dev special /dev..." mean in VCHR NAME columns? When lsof revision 4.53 and above comes across an open VCHR file whose device, raw device and inode place it somewhere other than /dev (or /devices), lsof doesn't report the /dev special device name in the NAME column. Instead lsof reports the file system name and device or path name in the NAME column and parenthetically adds "like dev special ". The value for will point to a device special file in /dev (or /devices) whose raw device number matches that of the open VCHR file being reported, but whose device number or node number (or both) don't match. Such an open VCHR file is connected to a device special file that has been created in a directory other than /dev (or /devices.) See mknod(8) for information on how such device special files are created. (Generally one needs root power to create device special files with mknod.) 3.34 Why does an lsof make fail because of undefined symbols? When lsof is compiled via the `make` step and the final load step fails because of missing symbols, the problem may not be lsof. The problem may be that ld, called by the compiler as part of the `make` step, can't find some library that lsof needs. First check the last compiler line of the make operation -- e.g., the last line with cc or gcc in it before the undefined symbol report -- for loader arguments, i.e., ones beginning with "-l". Except for "-llsof" the rest name system libraries. ("-L./lib" precedes "-llsof" to tell the loader its location.) Check that all the named system libraries exist. Look in /lib and /usr/lib as a start, but that may not be the only place system libraries live. Consult your dialect's documentation, e.g., the compiler and loader man pages, for other possible locations. If some system library doesn't exist, that may mean it was never installed or was removed. You'll have to re-install the missing library. You may find that all the system libraries lsof uses exist. Your next step might be to use nm and grep to see if any of them contain the undefined symbols. $ nm library | grep symbol If the undefined symbol exists in some library named by the lsof make step, then you might have a problem with some environment variable that controls the load step. The most common is LD_LIBRARY_PATH. It may have a setting that causes ld to ignore a directory containing a library lsof names. If this is the case, try unsetting LD_LIBRARY_PATH in the environment of the ld process -- e.g., do: $ unset LD_LIBRARY_PATH or % unsetenv LD_LIBRARY_PATH Consult your ld man page for other environment variables that might affect library searching -- e.g., LIBPATH, LPATH, SHLIB_PATH, etc. If the undefined function doesn't exist in any libraries lsof names, check other libraries. See if the function has a man page that names its library. If the latter is true, please let me know, because that is an lsof problem I need to fix. If none of these solutions work for you, send me some documentation via e-mail at . Include `uname -a` output, the output of the lsof `Configure ...` and `make` steps, and the contents of the environment in force when the `make` step was executed -- e.g., `env` or `printenv` output. If you've located the libraries lsof names, send me that information, too. 3.35 Command Regular Expressions (REs) 3.35.1 What are basic and extended regular expressions? Lsof's ``-c'' option allows the specification of regular expressions (REs), enclosed in two slash ('/') characters and followed by these modifiers: b the RE is a basic RE. i ignore case. x the RE is an extended RE (the default). Note: the characters of the regular expression may need to be quoted to prevent their expansion by the shell. Example: this RE is an extended RE that matches exactly four characters, whose third may be an upper ('O') or lower case ('o') oh: -c /^..o.$/i For simplicity's sake, an RE that is acceptable to egrep(1) is usually called an extended RE. REs suitable for the old line editor, ed(1), are often called basic REs (and sometimes also called obsolete). These are some ways basic REs usually differ from extended REs. (There are other differences.) * `|', `+', `?', '{', and '}' are ordinary characters. * `^' is an ordinary character except at the beginning of the RE. * `$' is an ordinary character except at the end of the RE. * `*' is an ordinary character if it appears at the beginning of the RE. For more information on REs and the distinction between basic and extended REs, consult your dialect's man pages for ed(1), egrep(1), sed(1), and possibly regex(5) or regex(7). 3.35.2 Why can't I put a slash in a command regular expression? Since a UNIX command name is the last part of a path to the command's executable, the lsof command regular expression (RE) syntax uses slash ('/') to mark the beginning and end of an RE. Slash may not appear in the RE and the `\' back-slash escape is ineffective for "hiding" it. More likely than not, if you try to put a slash in an lsof command RE, you'll get this response: $ lsof -s/.\// ... lsof: invalid regexp modifier: / Lsof is complaining the the first character it found after the second slash isn't an lsof command RE modifier -- 'b', 'i', or 'x'. 3.35.3 Why does lsof say my command regular expression wasn't found? When you use both forms of lsof's -c option -- ``-c '' and ``-c /RE/[m]'' -- and ask that lsof do a verbose search (``-V''), you may be surprised that lsof will say that the regular expression wasn't found. This can happen if the ``-c '' form matches first, because then the ``-c/RE/[m]'' test will never have been applied. For example: $ ./lsof -clsof -c/^..o.$/ -V -adcwd COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME lsof 7850 abe cwd VDIR 6,0 2048 96442 / (/dev/sd0a) lsof: no command found for regex: ^..o.$ The ``-clsof'' option matched first, so the ``-c/^..o.$/ option wasn't tested. 3.36 Why doesn't lsof report on shared memory segments? Lsof reports on shared memory segments only if they're associated with an open file. That's consistent with lsof's mission -- to LiSt Open Files. Shared memory segments with no file associations aren't open files. That's not to say that a report on shared memory segments and their associated processes wouldn't be useful. But it calls for a new tool, not more baggage for lsof. 3.37 Why does lsof report two instances of itself? When you ask lsof to report all open files and it has permission to do so, you may see two lsof processes in the ouput. The processes are connected via pipes -- e.g., here's an HP-UX 11 example. COMMAND PID USER FD TYPE DEVICE ... ... lsof 29450 abe 7w PIPE 0x48732408 ... lsof 29450 abe 8r PIPE 0x48970808 ... ... lsof 29451 abe 6r PIPE 0x48732408 ... lsof 29451 abe 9w PIPE 0x48970808 ... The first process will usually be the lsof you initiated; the second, an lsof child process that is used to isolate its parent process from kernel functions that can block -- e.g., readlink() or stat(). Information to and from the kernel functions is exchanged via the two pipes. When the parent process detects that the child process has become blocked, it attempts to kill the child. Depending on the UNIX dialect that may succeed or fail, but the parent won't be blocked in any event. See the "BLOCKS AND TIMEOUTS" and "AVOIDING KERNEL BLOCKS" sections of the lsof man page for more information on why the child process is used and how you can specify lsof options to avoid it. (Caution: that may be risky.) 3.38 Why does lsof report '\n' in device cache file error messages? Lsof revisions prior to 4.58 may report '\n' in error messages it delivers about problems in the device cache file -- e.g., lsof: WARNING: no ...: 4 sections\n That's deliberately done to show the exact contents of the device cache file line about which lsof is complaining, including its terminating NL (New Line) '\n' character. In the above example the line in the device cache file causing the lsof complaint contains "4 sections" and ends with a '\n'. At revision 4.58 and above, device cache error messages like the one in the above example have been changed to read: lsof: WARNING: no ...: line "4 sections" The terminal '\n' is no longer reported, the line contents are enclosed in double quote marks ('"'), and the word "line" has been added as a prefix to denote that what follows is a line from the device cache file. 3.39 Kernel Symbol and Address Problems 3.39.1 What does "lsof: WARNING: name cache hash size length error: 0" mean? When run on some systems, lsof may issue this warning: lsof: WARNING: name cache hash size length error: 0 That is an example from a FreeBSD system where lsof reads the kernel's _nchash variable and finds its value is zero. Similar warnings include: WARNING: kernel name cache size: WARNING: can't read kernel's name cache: WARNING: no name cache address WARNING: name cache hash size length error: WARNING: unusable name cache size: These warnings are issued when lsof is attempting to read the kernel's name cache information. They are usually the result of a mis-match between the addresses for kernel symbols lsof gets via nlist(2) and the addresses in use by the kernel. Lsof usually gets kernel symbol addresses from what it believes to be the kernel boot file. In FreeBSD, for example, that's the path returned by getbootfile(3), usually /kernel. The boot file can have other names in other UNIX dialects -- /unix, /vmunix, /bsd, /netbsd, /mach, /stand/vmunix, etc. Lsof will get incorrect (mismatched) addresses from the boot file if it has been replaced by a newer one which hasn't yet been booted -- e.g., if this is done in FreeBSD: # mv /kernel /kernel.OLD # mv /kernel.NEW /kernel Until the FreeBSD system is rebooted, the booted kernel is /kernel.OLD, but getbootfile() says it is /kernel. If symbol addresses important to lsof in /kernel.OLD and /kernel don't match, the lsof WARNING messages result. 3.39.2 Why does lsof produce "garbage" output? Kernel name cache warnings may not be the only sign that lsof is using incorrect symbol addresses to read kernel values. If there's no reasonable test lsof can make on what it reads from the kernel, it may issue other warnings or even report nonsensical results. The warnings may appear on STDERR, such as: lsof: can't read proc table info Or the warnings may appear in the NAME column as messages saying lsof can't read or interpret some kernel structure -- e.g., ... NAME ... can't read file struct from 0x12345 One possible work-around is to point lsof's kernel symbol address gathering at the proper boot file. That can be done with lsof's -k option -- e.g., $ lsof -k /kernel.OLD The best work-around is to make sure the standard boot file is properly sited -- e.g., if you've moved a new /kernel in place, boot it. 4.0 AIX Problems 4.1 What is the Stale Segment ID bug and why is -X needed? Kevin Ruderman reports that he has been informed by IBM that processes using the AIX 3.2.x, 4.1[.12345]], 4.2[.1], and 4.3.x kernel's readx() function can cause other AIX processes to hang because of what appears to be file system corruption. This failure, known as the Stale Segment ID bug, is caused by an error in the AIX kernel's journalled segment memory handler that causes the kernel's dir_search() function erroneously to believe directory entries contain zeroes. The process using the readx() call need not be doing anything wrong. Usually the system must be under such heavy load that the segment ID being used in the readx() call has been freed and then reallocated to another process since it was obtained from kernel memory. Lsof uses the readx() function to access library entry structures, based on the segment ID it finds in the proc structure of a process. Since IBM probably will never fix the kernel bug, I've added an AIX-specific option to lsof that controls its use of the readx() function. By default lsof readx() use is disabled; specifying the ``-X'' option enables readx() use. If you want to change the default readx() behavior of AIX lsof, change the HASXOPT, HASXOPT_ROOT, and HASXOPT_VALUE definitions in dialects/aix/machine.h. You can also use these definitions to enable or disable readx() -- consult the comments in machine.h. You may want to disable readx() use permanently if you plan to make lsof publicly executable. When HASXOPT_ROOT is defined, lsof will restrict use of the -X option to processes whose real UID is root; if HASXOPT_ROOT isn't defined, any user may specify the -X option. The Customize script offers the option to change HASXOPT_ROOT when HASXOPT is defined and HASXOPT_ROOT is named in any dialect's machine.h header file. I have never seen lsof cause a problem with its use of readx(), but I believe there is some chance it could, given the right circumstances. 4.1.1 Stale Segment ID APAR Here are the details of the Stale Segment ID bug and IBM's response, provided by Kevin Ruderman . AIX V3 APAR=ix49183 user process hangs forever in kernel due to file system corruption STAT=closed prs TID=tx2527 ISEV=2 SEV=2 (A "closed prs" is one closed with a Permanent ReStriction.) RCOMP=575603001 aix v3 for rs/6 RREL=r320 AIX V4 (internal defect, no apar #) prefix p name 175671 abstract KERMP: loop for ever in dir_search() Problem description: 1. Some user application -- e.g., lsof -- gets the segment ID (SID) for the process private segment of a target process from the process table. 2. The target process exits, deleting the process private segment. 3. The SID is reallocated for use as a persistent segment. 4. The user application runs again and tries to read the user area structure from /dev/mem, using the SID it read from the process table. 5. The loads done by the driver for /dev/mem cause faults in the directory; new blocks are allocated; the size changed; and zero pages created. 6. The next application that looks for a file in the affected directory hangs in the kernel's dir_search() function because of the zero pages. This occurs because the kernel's dir_search() function loops through the variable length entries one at a time, moving from one to the next by adding the length of the current entry to its address to get the address of the next entry. This process should end when the current pointer passes the end of the known directory length. However, while the directory length has increased, the entry length data has not, so when dir_search() reaches the zero pages, it loops forever, adding a length of zero to the current pointer, never passing the end of the directory length. The application process is hung; it can't be killed or stopped. IBM closed the problem with a PRS code (Permanent ReStriction) under AIX Version 3 and had targeted a fix for AIX 4.2. They have recently (I became aware of it September 10, 1996) cancelled the defect report altogether and have indicated they are not going to fix the defect. 4.2 Gcc Work-around for AIX 4.1x When gcc is used to compile lsof for AIX 4.1x, it doesn't align one element of the user structure correctly. Xlc sees the U_irss element as a type "long long" and aligns it on an 8 byte boundary. That's because the default mode of xlc is -qlonglong; when -qlonglong is enabled, the _LONG_LONG symbol is also defined. Gcc sees U_irss as a two element array of type long, because _LONG_LONG isn't defined. Hence gcc aligns the U_irss element array on a 4 byte boundary, rather than an 8 byte one, making the gcc incantation of the user structure 4 bytes shorter than xlc's. When the length of gcc's user structure is supplied as argument 4 to the undocumented getuser() function of the AIX kernel, getuser() rejects it as an incorrect size and returns EINVAL. Lsof has a work-around for this problem. It involves a special test in the Configure script when the "aixgcc" Configure abbreviation is used -- e.g., $ Configure -n aixgcc The test is to compile a small program with gcc and check the alignment of U_irss. If it's not aligned on an 8 byte boundary, the Configure script makes a special copy of in ./dialects/aix/aix whose U_irss will align properly, and generates compile time options to use it. While I have tested this work-around only with 4.1.4, it should work with earlier versions of AIX 4.1. It does not work for AIX 4.2; a different work-around is employed there. (See the next section.) If you want to use this technique to compile other AIX 4.1x programs with gcc for using getuser(), check the Configure script. Stuart D. Gathman identified this gcc AIX alignment problem. 4.3 Gcc and AIX 4.2[.1] Alignment problems with gcc and AIX 4.2[.1] inside the user structure are more severe, because there are some new 64 bit types in AIX that gcc doesn't yet (as of 2.7.x) support. The U_irss element problem, discussed in 4.3 above, doesn't exist in 4.2[.1]. The AIX lsof machine.h header file has a work-around, provided by Henry Grebler , that bypasses gcc alignment problems. Later versions of gcc (e.g., 2.8.x) will probably bypass the problems as well. 4.4 Why won't lsof's Configure allow the use of gcc for AIX below 4.1? Gcc can't reliably be used to compile lsof for AIX versions below AIX 4.1 because of possible kernel structure element alignment differences between it and xlc. 4.5 What is an AIX SMT file type? When you run AIX X clients with the DISPLAY environment variable set to ``:0.0'' they communicate with the AIX X server via files whose kernel file structure has an undefined type (f_type == 0xf) -- at least there's no definition for it in . These are Shared Memory Transport (SMT) sockets, an artifact of AIXWindows, designed for more efficient data transfers between the X server and its clients. Henry Grebler and David J. Wilson alerted me to the existence of these files. Mike Feldman and others helped me identify them as SMT sockets. The curious reader can find more about SMT sockets in /usr/lpp/X11/README.SMT. 4.6 Why does AIX lsof start so slowly? When AIX lsof starts it compares the running kernel's identity to the one for which it was built, using /usr/bin/oslevel. That comparison can sometimes take a long time to complete, depending on the system's maintenance level and how recently it was examined with oslevel. You can skip the oslevel test by suppressing warning messages with lsof's -w option. Doing that carries with it the risk of missing other warning messages, however. You can also disable the kernel identity check by disabling the definition of the HASKERNIDCK symbol by editing AIX machine.h header file or by using the Customize script to disable it. See the "Why does lsof warn "compiled for x ... y; this is z.?" section for more information. 4.7 Why does exec complain it can't find libc.a[shr.o]? When you try to execute lsof you may get this complaint: exec(): 0509-036 Cannot load program ./lsof because of the following errors: 0509-022 Cannot load library libc.a[shr.o]. 0509-026 System error: A file or directory in the path name does not exist. This is probably the result of making lsof when the LIBPATH environment variable contained a directory path that doesn't contain libc.a. You can see what LIBPATH contained when lsof was made by using the dump application on lsof. For example, if LIBPATH contained /foo/bar when lsof was made, you will see this (partial) dump output: $ dump -H lsof ... ***Import File Strings*** INDEX PATH BASE ... 0 /foo/bar To correct the problem, revisit the lsof source directory and remake lsof this way: $ unset LIBPATH; make (sh or ksh) or % unsetenv LIBPATH; make (csh or tcsh) 4.8 What does lsof mean when it says, "no PCB, CANTSENDMORE, CANTRCVMORE" in a socket file's NAME column? When an AIX application calls shutdown(2) on an open socket file, but hasn't called close(2) on the file, the file will remain visible to lsof as an open socket file without any extended protocol information. Lsof reports that state in the NAME column by saying that there is "no PCB" (Protocol Control Block) for the protocol (e.g., TCP in the NODE column). If the open socket file has the state variables SO_CANTSENDMORE and SO_CANTRCVMORE set -- i.e., from the shutdown(2) call -- lsof reports them with the CANTSENDMORE and CANTRCVMORE notes in the NAME column. 4.9 When the -X option is used on AIX 4.3.3, why does lsof disable it, saying "WARNING: user struct mismatch; -X option disabled?" The -X option causes lsof to read the loader information of the user structure from virtual memory via the readx() system call. It does that with the user structure definition from that was compiled into the lsof executable. On AIX 4.3.3 there are two different user structure definitions in two separate header files, distributed at different times by IBM. If lsof was compiled with one and the kernel on which lsof is being run was compiled with the other, lsof normally won't get correct loader information when it calls readx(). In an attempt to compensate for that difference, lsof makes an independent check of the loader information by getting the user structure's open file count via readx() and comparing it to the open file count obtained independently via getprocs(). When the two counts don't match, lsof tries to read the count (and re-read the loader information) with two offsets, based on observed differences between the two user structures. When one of the three attempts produces a correct open file count, lsof uses its corresponding offset on subsequent readings of the loader information. When none of the three attempts produces a correct open file count, lsof issues the WARNING message and disables -X processing. To eliminate this problem, obtain an lsof binary that matches the kernel of the AIX 4.3.3 system where you want to run lsof. Compiling lsof on the target system is the preferred way to get a matching binary. 4.10 Why doesn't the -X option work on my AIX 5L or 5.1 system? If your AIX 5L or 5.1 system uses the ia64 architecture, lsof needs setuid-root permission to be able to do the processing that -X requires. Check the output of `uname -a` to determine the architecture type. The work-around is to give lsof setuid-root permission. 4.11 Why doesn't /usr/bin/oslevel report the correct AIX version? The oslevel man page says, "The oslevel command reports the level of the operating system using a subset of all filesets installed on your system." You can see which fileset is below the expected level with oslevel's -l option. For example, if you believe your system is at AIX level 4.3.3, but oslevel reports 4.3.2, use this oslevel command to find the filesets below 4.3.3: $ /usr/bin/oslevel -l 4.3.3.0 If you don't know what level argument to supply to oslevel's -l option, use oslevel's -q option first. 4.11.1 Why doesn't /usr/bin/oslevel report the correct AIX version on AIX 5.1? The subset list for oslevel on AIX 5.1 seems to include at least two filesets, xlsmp.msg.en_US.rte and xlsmp.rte, that do not install from AIX 5.1 media with a 5.1.0.0 level. Hence, oslevel reports 5.0.0.0 instead of the expected 5.1.0.0. If either xlsmp.msg.en_US.rte or xlsmp.rte is installed, lsof's Configure script and run-time tests will identify the AIX version incorrectly. The run-time test will issue a complaint message of this form: lsof: WARNING: compiled for AIX version xxx; this is yyy. You can correct the Configure test by pre-defining the oslevel value, setting the correct value in the LSOF_VSTR environment variable before running the Configure script -- e.g., to pre-define AIX 5.1 when using ksh, do this: $ LSOF_VSTR=5.1.0.0 Configure -n aix You can't affect oslevel output without uninstalling xlsmp.msg.en_US.rte and xlsmp.rte. If you can't do that, you'll have to put up with the run-time complaint. 4.12 Why does lsof for AIX 5.1 Power architecture complain about kernel bit size? When you run an lsof binary on an AIX 5.1 Power system, it might complain: lsof: FATAL: compiled for a 32 bit kernel. The bit size of this kernel is 64. or exec: 0509-036 Cannot load program ./lsof because of the following errors: 0509-032 Cannot run a 64-bit program on a 32-bit machine. Starting at lsof revision 4.61, lsof binaries for Power architecture systems running AIX 5.1 or above are closely tied to the kernel bit size. Lsof must do that so it can read and understand kernel structures. Lsof's Configure script tunes the lsof configuration so that the binary built in the make(1) step is adjusted to the kernel bit size. An lsof binary knows the bit size for which it was constructed, tests the bit size of the kernel under which it is running, and objects if the two sizes don't match. To see the bit size for which lsof was constructed, run it with its -v option and look for these lines in the output: configuration info: 32 bit kernel or configuration info: 64 bit kernel (Note: these lines will appear only in -v output for AIX 5.1 and above lsof binaries, built for Power architecture.) You can see the kernel bit size test method in the aix stanza of the lsof Configure script and in the get_kernel_access() function of the lsof .../dialects/aix/dproc.c source file. There is more information on pre-defining the kernel bit size when building lsof in Configure, 00PORTING, and 00XCONFIG. The only work-around is to use an lsof binary built to match the running kernel bit size. 4.13 What can't gcc be used to compile lsof on the ia64 architecture for AIX 5 and above? Gcc can't be used to compile lsof on the ia64 architecture for AIX 5 and above because I haven't had access to a system that has a working gcc compiler. The gcc compiler on my one and only ia64 AIX 5.1 test system, provided by IBM, doesn't work at all. 4.14 Why does lsof get a segmentation fault when compiled with gcc for a 64 bit Power architecture AIX 5.1 kernel? When lsof is configured with the lsof "aixgcc" Configure abbreviation, the resulting lsof executable may cause a segmentation violation when it is run. I've observed this with gcc version 2.9-aix43-010414-7. As far as I have been able to tell, the segmentation fault is the result of a gcc compilation, loading, or library error. Watching lsof run with gcc's companion debugger, gdb, shows no error in the lsof source code that might explain the fault. The only work-around I know is to use the IBM C compiler in place of gcc -- i.e., use the "aix" lsof Configure abbreviation. 5.0 Apple Darwin Problems 5.1 Why does Configure have to check out CVS kernel header files? When lsof was ported to Apple Darwin by Allan Nathanson at revision 4.53, some kernel header files needed by lsof weren't being exported by the developers. Allan provided a shell script, get-xnu-headers.sh, to check them out from the CVS root. I enhanced that script. If all the header files exist, the Configure script will avoid the CVS checkout steps. 5.1.1 Why won't CVS let the Apple Darwin lsof Configure step check out header files? To check out files you must be a registered Darwin user and must have successfully completed `cvs login` once. To learn how to become a registered Darwin user and how to use CVS, consult this URL: http://www.opensource.apple.com/tools/cvs/docs.html Of course, if lsof's get-xnu-headers.sh script can't contact the Darwin CVSROOT, that will also block CVS check out. 5.1.2 What CVS branch should I specify for Apple Darwin kernel header file checkout? The suggested branches, xnu-3 for Public Beta (Kodiak1H39) and xnu-3-1 for Darwin 1.2.1, should be sufficient. You can tell which Darwin version you are running with the "-a" option to the uname command -- e.g., $ uname -a Darwin 1.2 Darwin Kernel Version 1.2: \ Wed Aug 30 23:32:53 PDT 2000; \ root:xnu/xnu-103.obj~1/RELEASE_PPC \ Power Macintosh powerpc The "xnu-103" after "root:xnu" corresponds to the xnu-3 branch. 5.1.3 How can I supply the missing Apple Darwin kernel header files myself? When the missing Apple Darwin kernel files are fetched from the CVS root, they are stored in dialects/darwin/include. You should be able to duplicate that tree if you can obtain the missing header files yourself. The missing header files are identified in the darwin stanza of the lsof Configure script. Look for this comment: # Make sure XNU headers are present. The next line sets the shell variable LSOF_TMP1 to a list of the header files. The list includes their paths relative to the head of an include tree. The following shell code checks for the header files in their "standard" location and in dialects/darwin/include. If any are missing, Configure calls the get-xnu-headers.sh script to fetch a matching set. 5.2 Why doesn't Apple Darwin lsof report text file information? At the first port of lsof to Apple Darwin, revision 4.53, insufficient information was available -- logic and header files -- to permit the installation of VM space scanning for text files. Text file support will be added to Apple Darwin lsof after the necessary information becomes available. 5.3 Why doesn't Apple Darwin lsof support IPv6? At the first port of lsof to Apple Darwin, revision 4.53, Apple Darwin lacked IPv6 support. IPv6 support will be added to Apple Darwin lsof after it has been made available in Apple Darwin. 5.4 Why does lsof complain about a mismatch between the release for which lsof was compiled and the booted Max OS X release? When lsof is started on the "Gold Master" Darwin release (aka Mac OS X), it complains: lsof: compiled for 1.0 release; this is 1.3.2. This happens because the lsof binary released with Mac OS X was built on a system whose release number (1.0) doesn't match that of the released system -- usually 1.3.x Lsof makes this check because UNIX dialect OS changes are often accompanied by header file changes that affect lsof. In this specific case, this error can be ignored. If you don't want to do that, get the lsof distribution and build lsof so its built-on and running-on Mac OS X release numbers match. 6.0 BSD/OS BSDI Problems 6.1 Why doesn't lsof report on open kernfs files? Lsof doesn't report on open BSD/OS BSDI kernfs files because the structures lsof needs aren't defined in the kernfs.h header file in /sys/misc/kernfs. 7.0 DEC OSF/1, Digital UNIX, and Tru64 UNIX Problems 7.1 Why does lsof complain about non-existent /dev/fd entries? When you run lsof for Digital UNIX 3.2, lsof may complain: lsof: can't lstat /dev/fd/xxx: No such file or directory lsof: can't lstat /dev/fd/yyy: No such file or directory (Or it may warn about other missing /dev/fd paths.) When you do an ``ls /dev/fd'' none of the missing paths are listed. This is caused by a bug in the DEC library function getdirentries(). For some reason, when /dev/fd is a file system mount point, getdirentries() returns an incorrect size for it to readdir(). (Lsof calls readdir() in its ddev.c readdev() function.) Because of the incorrect size, readdir() goes past the end of the /dev/fd directory buffer, encounters random paths and returns them to lsof. Lsof then attempts to lstat(2) the random paths, gets error replies from lstat(2), and complains about the paths. Duncan McEwan discovered this error and has reported it to DEC. Duncan also supplied a work- an alternate readdir() function as a work-around. I've incorporated his readdir() in dialects/osf/ddev.c (as the static ReadDir() function) with some slight modifications, and enabled its use when the USELOCALREADDIR symbol is defined. The Configure script defines USELOCALREADDIR for Digital UNIX version and 3.2. If you don't want to use Duncan's local readdir() function, edit the Makefile and remove -DUSELOCALREADDIR from the CFGF string. When DEC releases a corrected getdirentries() function, I'll modify the Configure script to stop defining USELOCALREADDIR. 7.2 Why does the Digital UNIX V3.2 ld complain about Ots* symbols? When you compile lsof on your Digital UNIX V3.2 system, ld may complain: ld: Unresolved: knlist _OtsRemainder32Unsigned _OtsDivide64Unsigned _OtsRemainder64Unsigned _OtsDivide32Unsigned _OtsMove _OtsDivide32 _OtsRemainder32 *** Exit 1 Chris Eleveld reports this happens on Digital UNIX V3.2 systems after the Fortran compiler has been installed. The best work-around seems to be to remove -lmld from the CFGL string in the Makefile produced by Configure -- i.e., change: CFGL= -lmld to CFGL= According to the V3.2 man page for nlist(3), this shouldn't work, but my testing shows that it does. Although I haven't been able to test this second work-around, you might try adding -lots to CFGL, rather than removing -lmld -- i.e., change: CFGL= -lmld to CFGL= -lmld -lots WARNING: my testing also shows that the V2.0 nlist(3) man page means what it says when it calls for -lmld -- lsof loaded without -mld under V2.0 can't locate the proc (process) table address. DON'T REMOVE -lmld FROM THE DIGITAL UNIX V2.0 MAKEFILE. If you run into this problem, please let me know what problem you encountered and how you solved it. 7.3 Why can't lsof locate named pipes (FIFOs) under V3.2? While lsof for V3.2 can report on named pipes (FIFOs), it can't find them by name. That appears to happen because of the way the V3.2 kernel lstat(2) function reports named pipe device numbers. The V3.2 kernel reports the device number as 0xfffffff, while the kernel structures for named pipes that lsof examines contain the device number of the file system on which the named pipe resides. Consequently, lsof can't match the device and inode number pair it receives from applying lstat(2) to the named pipe with any device and inode number pair it finds when scanning kernel structures. I don't have a work-around. You can, of course, ask for full lsof output and use a post-processing filer (e.g., grep) to locate the named pipe of interest. This problem doesn't exist under V2.0. 7.4 Why does lsof use the wrong configuration header files? For example, why can't the lsof compilation find cpus.h? DEC OSF/1, Digital UNIX, and Tru64 UNIX configuration header files describe the hardware and software environment for which your kernel boot file was constructed. For example, /sys//cpus.h defines the number of CPUs in its NCPUS #define. Lsof searches for the configuration header file subdirectory in /sys (/usr/sys for Digital UNIX version 4.0 and Tru64 UNIX) by converting the first host name component to capital letters -- e.g., TOMIS is derived from tomis.bio.purdue.edu. If that subdirectory exists, lsof uses header files from it. (Configure reports what subdirectory is being used.) If Configure doesn't find a host-name derived subdirectory, it prompts you for the entry of a subdirectory name. If you can't find one, quit Configure and run the kernel generation process to create a proper configuration sub- directory. If you don't identify a proper configuration subdirectory and you try to compile lsof, the compiler will complain about missing header files -- e.g., a missing cpus.h. Once you have located or generated a proper configuration subdirectory, rerun Configure. If you have generated a configuration subdirectory whose name is derived from the host name, Configure will find and use it. If not, you will have to specify its name to Configure. 7.5 Why does lsof indicate incomplete paths with " -- " for Tru64 UNIX 5.1 files? When lsof can't find a component of a path in the kernel's name cache (aka DNLC), or can't determine that the left-most component has as its parent the file system root, it uses an "incomplete path" notation. That notation begins with the file system root name, followed by " -- ", followed by the consecutive path name components lsof was able to find in the DNLC -- e.g., "/ -- init". Because the DNLC was significantly redesigned in Tru64 UNIX 5.1, lsof's handling of the cache had to be completely redone. As part of the DNLC redesign a name cache entry parameter lsof formerly used to locate the file system root of a path was removed. With help from Chang Song I've been able to implement an alternate method for detecting the root of these file system types: AdvFS (MSFS), CDFS, DVDFS, FDFS, NFS, NFS3, and UFS. When lsof doesn't know how to identify the root for a file system type, it will resort to the " -- " incomplete path notation. 7.6 Why doesn't lsof report link count, node number, and size for some Tru64 5.x CFS files? Lsof reports link count, node number, and size for open CFS files as recorded in their kernel node structure's cached attributes. Sometimes not all attributes are cached on the system where lsof runs, so lsof cannot report them. 7.7 Why does lsof say it can't read the kernel name list on Digital UNIX 4.x or Tru64 UNIX? By default on Digital UNIX 4 and Tru64 UNIX lsof reads the addresses for kernel symbols with the knlist(3) function. That function can fail, for example, when the kloadsrv daemon isn't running or is malfunctioning. When that happens, lsof will abort with the error message: lsof: can't read kernel name list from knlist(3): ... If you know the name of the file from which the running system was booted, e.g., /vmunix, you can use lsof's -k option to direct it to read kernel symbol adresses from the name list of that file -- $ lsof -k /vmunix ... If that works, then knlist(3) is malfunctioning. 8.0 FreeBSD Problems 8.1 Why doesn't lsof report on open kernfs files? Lsof doesn't report on open FreeBSD kernfs files because the structures lsof needs aren't defined in the kernfs.h header file in /sys/misc/kernfs. 8.2 Why doesn't lsof work under FreeBSD 4.0? If lsof doesn't work under FreeBSD 4.0, first make sure you have the latest lsof revision, 4.41 or higher. Next check that your kernel and libkvm are in proper synchronization. Recompile them, if necessary. You might also try compiling lsof this way: $ make DEBUG="-O -DCOMPAT_LINUX_THREADS" Strictly speaking, -DCOMPAT_LINUX_THREADS shouldn't be needed, but slightly unsynchronized FreeBSD 4.0 kernels, header files, and libraries may make it necessary. 8.3 Why does Configure abort on FreeBSD 5.0 for lack of devfs.h? If lsof's Configure script can't find the devfs.h header file for FreeBSD 5.0 in /usr/include/fs/devfs or /sys/fs/devfs, it aborts. Without devfs.h, when lsof encounters open files on devfs file systems, including /dev, lsof cannot collect the expected information. The work-around is to install the FreeBSD kernel source tree in /sys, thus making /sys/fs/devfs/devfs.h available. 9.0 HP-UX Problems 9.1 What do /dev/kmem-based and PSTAT-based mean? Lsof for HP-UX 11.0 and below uses /dev/kmem to read kernel data structures from which it gathers and reports open file information. That version of lsof is called /dev/kmem-based lsof. Starting with HP-UX 10.10, finding definitions for the necessary kernel structures became more difficult as HP no longer distributed header files in /usr/include that defined all kernel structures. So I started "inventing" structure definitions by using Q4 to display them. By HP-UX 11, the process of invention became extremely intensive to support. Following a patch to the ipc_s structure in early 1999, my invented definition of that structure became incorrect. Although I was able to devise a work-around test for the patch with Q4, it was clear that my inventions were bound to cause more problems. Discussion with HP about the patch led to my proposing that an lsof API in the HP-UX kernel was the proper solution. Much to my surprise, HP agreed. I believe Carl Davidson was the prime mover behind that decision, but I know others participated, among them Louis Huemiller, Rich Rauenzahn, and Sailu Yallapragada. I am indebted to these folks and HP for their willingness to do this work. The API was added to the PSTAT interface in a project named PEGL, Pstat Enhancements for Glance and Lsof. Louis and Sailu did the bulk of the design and implementation work and testing began in March, 2000 HP-UX 11.11 is the first version that provides PSTAT support for lsof. HP-UX versions in between 11.0 and 11.11 -- all Beta versions as far as I can determine -- have no lsof support. See the "PSTAT-based HP-UX lsof Questions" section for questions and answers specific to PSTAT-based HP-UX lsof. The next section, "Why doesn't a /dev/kmem-based HP-UX lsof compilation use -O?" covers /dev/kmem-based HP-UX lsof. 9.2 /dev/kmem-based HP-UX lsof Questions The sources for /dev/kmem-based lsof for HP-UX may be found in lsof_/dialects/hpux/kmem. Lsof's Configure shell script decides to use these sources when it finds that the /usr/include/sys/pstat subdirectory doesn't exist. Lsof can be forced to use the /dev/kmem sources by setting "/dev/kmem" in the HPUX_BASE environment variable. Consult the Configure shell script and 00XPORTING for more information. 9.2.1 Why doesn't a /dev/kmem-based HP-UX lsof compilation use -O? If you only have the standard (bundled) HP-UX C compiler and haven't purchased and installed the optional one, then you can't use cc's -O option. The HP-UX cc(1) man page says this: "Options Note that in the following list, the cc and c89 options -A , -G , -g , -O , -p , -v , -y , +z , and +Z are not supported by the C compiler provided as part of the standard HP-UX operating system. They are supported by the C compiler sold as an optional separate product." Lsof's Configure script tries to detect what C compiler product you have installed by examining your compiler. If that examination reveals a standard (bundled) compiler, lsof avoids using -O. If the Configure compiler test fails, the C compiler will complain that it doesn't support -O. You can suppress that complaint by editing the Makefile produced by Configure and removing the DEBUG= -O make string. 9.2.2 Why doesn't the /dev/kmem-based lsof report HP-UX 10.20 locks correctly? Lsof doesn't report the length of HP-UX 10.20 locks -- byte or full file -- correctly under HP-UX 10.20 because the kernel structure lsof examines to determine that a process has a lock on a vnode (the locklist structure from ) contains incorrect lock start and end byte values. Even though this appears to be a kernel bug, HP-UX locks seem to work correctly. All I can conclude is that the correct lock information is stored somewhere else in the kernel, in a place not visible to lsof. As a consequence of this incorrect locklist structure information, lsof always reports all locks with a byte-level `r' (read) or `w' (write) lock indication, and never reports a full-file read (`R') or write (`W') lock. 9.2.3 Why doesn't the /dev/kmem-based CCITT support work under 10.x? Pasi Kaara , who originally provided the HP-UX CCITT support, reports that it no longer works under HP-UX 10.x. Consequently, at lsof revision 4.02 it has been disabled. 9.2.4 Why can't /dev/kmem-based lsof be compiled with `cc -Aa` or `gcc -ansi` under HP-UX 10.x? Some HP-UX 10.x header files, needed by lsof, can't be compiled properly in ANSI_C mode; structure element definition and alignment problems result. The f_offset member of the file structure, for example, is incorrect. This ANSI-C obstacle extends to using the -Aa option of the HP C compiler and the -ansi option of gcc. 9.2.5 Why does /dev/kmem-based lsof complain about no C compiler? Lsof's Configure script looks in /bin and /usr/ccs/bin for an HP C compiler, because it needs to know if the compiler is the standard (bundled) one or the optional separate product. If it finds no compiler in either place, Configure quits after complaining: No executable cc in /bin or /usr/ccs/bin If you don't have a C compiler in either of these standard places, you should consider installing it. If you have gcc installed, you can use it by declaring the ``hpuxgcc'' abbreviation to lsof's Configure script. If you have a C compiler in a non-standard location, you can use the HPUX_CCDIR[12] environment variables to name the path to it. Consult the 00XCONFIG file of the lsof distribution for more information. 9.2.6 Why does Configure complain about q4 for /dev/kmem-based lsof for HP-UX 11? When you run Configure on an HP-UX 11 system, it may complain: !!!ERROR!!! !!!ERROR!!! !!!ERROR!!! !!!ERROR!!! Configure can't use /usr/contrib/bin/q4 to examine the ipis_s structure. You must do that yourself, report the result in the HPUX_IPC_S_PATCH environment variable, then repeat the Configure step. Consult the Configure script's use of /usr/contrib/bin/q4 and the 00XCONFIG file for information on ipis_s testing and the setting of HPUX_IPC_S_PATCH. !!!ERROR!!! !!!ERROR!!! !!!ERROR!!! !!!ERROR!!! This message states that Configure cannot use q4 from /usr/contrib/bin to examine the kernel's boot image for the ipis_s structure. That structure was introduced in early 1999. Patch bundle B.11.00.43 and patches PHNE_20008 and PHNE_20735 appear to be responsible for ipis_s. Note: q4 may also fail if it can't execute nm -- e.g., it can't find /usr/bin/nm, or you have a conflicting, private version of nm earlier in your path. The ipis_s structure isn't described in any header file HP-UX releases with HP-UX 11. It appears in the private lsof header file .../dialects/hpux/kmem/hpux11/ipc_s.h. I had to create ipc_s.h during the lsof port to HP-UX 11 by using q4. Lsof gets local and remote connection addresses (IP and port numbers) from ipc_s, so an incorrect ipc_s definition may cause incorrect reporting of TCP/IP connection addresses. It definitely will cause incorrect reporting on 32 bit kernels. In any case lsof should be compiled with a correct ipc_s definition no matter the kernel bit size, so the Configure script always tests for it when the HP-UX version is 11. Over the long run -- e.g., after the current patch has been replaced by yet another one -- using q4 is the most reliable way to tell if ipis_s exists and what it contains. Unfortunately, q4 needs to be installed in /usr/contrib/bin and the kernel boot image, /stand/vmunix, needs to be processed with pxdb. If either is untrue, lsof issues the above error message, perhaps preceded by q4 messages. For example, if /stand/vmunix hasn't been processed by pxdb, the q4 messages will include: q4: (error) vmunix not pxdb'd or q4: (warning) /stand/vmunix has not been processed by pxdb. To be able to complete HP-UX configuration of lsof, you must determine if the ipis_s structure is defined in your kernel, if the ipis_s structure of your kernel has an ipis_msgsqueued member, and if the ipc_s structure of your kernel uses has an ipc_ipis member. That means you may have to process /stand/vmunix with pxdb, and perhaps install q4 and run it on /stand/vmunix. If you must run q4 to determine the state of ipis_s and ipc_s, use these q4 commands: $ /usr/contrib/bin/q4 /stand/vmunix ... q4> fields -c struct ipis_s ... q4> fields -c struct ipc_s Look in the q4 output for the ipc_ipis member of the ipc_s structure, and look in the ipis_s structure for the ipis_msgsqueued member. If ipc_s has ipc_ipis but ipis_s lacks ipis_msgsqueued, set HPUX_IPC_S_PATCH environment variable to "1". If ipc_s has ipc_ipis and ipis_s has ipis_msgsqueued, set HPUX_IPC_S_PATCH to "2" -- e.g., $ HPUX_IPC_S_PATCH=1 Configure -n hpux or $ HPUX_IPC_S_PATCH=2 Configure -n hpux or % setenv HPUX_IPC_S_PATCH 1 % Configure -n hpux or % setenv HPUX_IPC_S_PATCH 2 % Configure -n hpux (Use setenv if your shell is csh.) If ipc_s has no ipc_ipis member, set HPUX_IPC_S_PATCH to "N" -- e.g., use this Configure step: $ HPUX_IPC_S_PATCH=N Configure -n hpux or % setenv HPUX_IPC_S_PATCH N % Configure -n hpux 9.2.7 When compiling /dev/kmem-based lsof for HP-UX 11 what do the "aCC runtime: ERROR..." messages mean? When the lsof Makefile asks the HP-UX unbundled compiler to load lsof, it may complain: /bin/cc -o lsof -DHPUXV=1100 -DHASVXFS -DHPUXKERNBITS=64 \ -I/home/abe/src/lsof4/dialects/hpux/kmem/hpux11 +DD64 \ -DHAS_IPC_S_PATCH=2 -I/home/abe/src/lsof4/dialects/hpux/kmem \ -DLSOF_VSTR=\"B.11.00\" -g dfile.o dmnt.o dnode.o dnode1.o \ dnode2.o dproc.o dsock.o dstore.o arg.o main.o misc.o \ node.o print.o proc.o store.o usage.o -L./lib -llsof -lelf \ -lnsl aCC runtime: ERROR: Unexpected use of shared libraries aCC runtime: ERROR: Read aCC manpage, +A option /usr/lib/nls/loc/locales.1//is_IS.iso88591 This is a bug in the HP-UX national language support. (Notice the last message with "locales" in it?) Complain to HP -- then use this work-around before executing make: $ unset LANG $ make 9.2.8 Why doesn't /dev/kmem-based lsof for HP-UX 11 report VxFS file link counts, node numbers, and sizes correctly? This is usually the result of running an lsof binary whose revision number is less than 4.57 on a system that has OnlineJFS support installed. It can also happen with lsof 4.57 binaries when the OnlineJFS support with which they were built doesn't match the OnlineJFS status of the system on which they are run. The OnlineJFS status of lsof 4.57 and higher binaries can be determined by running: $ lsof -v 2>&1 | grep HASONLINEJFS If that shell pipe produces output, lsof was compiled with OnlineJFS support enabled; no output, disabled. If OnlineJFS is installed on an HP-UX 11 system the /sbin/fs/vxfs/subtype executable exists and outputs "vxfs3.3" when run. The problem occurs because the optional OnlineJFS support installation doesn't update . Consequently lsof can be compiled with an incorrect definition of the vx_inode structure and look for for link counts, node numbers, and sizes in the wrong places in the structure. The current response I have gotten from HP is that no update will be provided for OnlineJFS. I've addressed this problem temporarily with a work-around (hack) in lsof revision 4.57. 9.2.9 Why can't /dev/kmem-based lsof be built with gcc for 64 bit HP-UX 11? When Configure is given the "hpuxgcc" abbreviation, the HP-UX version is 11, and the kernel bit size is 64, the lsof Configure script may abort with the messages: !!!!!!!!!!!!!!!!! FATAL ERROR !!!!!!!!!!!!!!!!!! APPARENTLY GCC CANNOT BUILD 64 BIT EXECUTABLES. A COMPILER MUST BE USED THAT CAN. SEE 00FAQ FOR MORE INFORMATION. (This is the "more information" in 00FAQ.) This means the Configure script compiled a test program with gcc the result wasn't an ELF-64 binary. Lsof tries two gcc modes, one with no options and another with the -mlp64 option, before it concludes gcc can't be used. See the "How can I acquire a gcc for building lsof for 64 bit HP-UX 11?" answer for information on where you might be able to get a gcc for HP-UX 11 that can produce ELF-64 executables. 9.2.9.1 How can I acquire a gcc for building lsof for 64 bit HP-UX 11? Check this HP URL: http://h21007.www2.hp.com/dspp/tech/tech_TechSoftwareDetailPage_IDX/1,1703,547,00.html (That's one very long link; be careful you cut 'n paste it all.) In November 2001 that URL led to a web page whose title was "gcc for hp-ux 11." The page offered a link for downloading a 64 bit gcc 3.0 compiler for HP-UX 11.0 and 11i. Rich Rauenzahn of HP installed that compiler on an HP test system he allows me to use and I successfully built a 64 bit lsof with it. The HP package may install the 64 bit capable gcc in /usr/local/pa20_64/bin/gcc, so you may have to adjust your path or set the LSOF_CC environment variable to compensate. 9.3 PSTAT-based HP-UX lsof Questions The sources for PSTAT-based lsof for HP-UX may be found in lsof_/dialects/hpux/pstat. Lsof's Configure shell script decides to use these sources when it finds that the /usr/include/sys/pstat subdirectory exists. Lsof can be forced to use the PSTAT-based sources by setting "pstat" in the HPUX_BASE environment variable. Consult the Configure shell script and 00XPORTING for more information. 9.3.1 Why does PSTAT-based lsof complain about pst_static and other PSTAT structures? When lsof starts it may issue one of these fatal error messages: lsof: FATAL: can't determine PSTAT static size lsof: FATAL: can't read bytes of pst_static lsof: FATAL: pst_static doesn't contain _size lsof: FATAL: _size should be These messages indicate that lsof's tests for the proper level of PSTAT support have failed. The structure names, given in , and sizes, given in , identify the support deficiency more precisely. You may need to upgrade the PSTAT support in your kernel to be able to use PSTAT-based lsof. 9.3.2 Why does PSTAT-based lsof complain it can't read pst_* structures? Lsof may put messages like the following in the NAME column of its output. can't read cwd pst_filedetails: Permission denied can't read mem pst_filedetails: Permission denied can't read rtd pst_filedetails: Permission denied can't read txt pst_filedetails: Permission denied can't read pst_filedetails: Permission denied can't read 3 stream structures: Permission denied can't read pst_socket: Permission denied These messages indicate that the lsof binary lacks the authority to read the name structures for processes other than ones belonging to the UID under which lsof is running. Authority to read the structures of other processes is limited to root processes -- i.e., lsof must have setuid-root permission if it is to list open files for arbitrary processes. If you want to eliminate these errors, you must run lsof as root or install it wi