The fuser
command lets me know which processes are using a file or directory.
I'm looking for command that does the opposite: lets me know which files are being used by a process.
Forgot to mention that it's for a Solaris system.
UNIX List Open Files For Process First use the ps command command to get PID of process, enter: $ ps -aef | grep {process-name} $ ps -aef | grep httpd
Conclusion Category List of Unix and Linux commands Documentation help • man • pinfo Disk space analyzers df • duf • ncdu • pydf File Management cat • cp • mkdir • tree Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHE ... 9 more rows ...
Whenever a command is issued in unix/linux, it creates/starts a new process. For example, pwd when issued which is used to list the current directory location the user is in, a process starts. Through a 5 digit ID number unix/linux keeps account of the processes, this number is call process id or pid. Each process in the system has a unique pid.
The fuser command lets me know which processes are using a file or directory. I'm looking for command that does the opposite: lets me know which files are being used by a process. Forgot to mention that it's for a Solaris system. Show activity on this post.
lsof -p <pid>
From here
lsof stands for “LiSt Open Files”. This shell command seems deceptively simple: It lists information about files opened by processes on a UNIX box.
Despite its (apparent) modest mission statement, lsof is actually one of the most powerful and useful UNIX commands. Its raw power comes from one of UNIX’s design principle often described as ”in UNIX everything is a file”. What this means is that the lsof concept of an open file not only covers regular files but also the following:
Wait, I Cannot Find lsof on My System!
lsof is such a popular tool that it has been ported to pretty much all UNIX dialects (Linux, Mac OS X, BSD, Solaris, and so on). If it is unavailable on your box, use your usual package management system to install it. You can find lsof packages for Solaris on Sun Freeware.
While I wouldn't begrudge anyone learning Dtrace or gaining experience installing software, in Solaris there is a command to see the files a process has open: /usr/bin/pfiles
% tail -f /etc/motd &
[1] 6033
% pfiles 6033
6033: tail -f /etc/motd
Current rlimit: 256 file descriptors
0: S_IFREG mode:0644 dev:182,65538 ino:163065 uid:0 gid:3 size:54
O_RDONLY|O_LARGEFILE
/etc/motd
1: S_IFCHR mode:0620 dev:299,0 ino:718837882 uid:101 gid:7 rdev:24,3
O_RDWR|O_NOCTTY|O_LARGEFILE
/dev/pts/3
2: S_IFCHR mode:0620 dev:299,0 ino:718837882 uid:101 gid:7 rdev:24,3
O_RDWR|O_NOCTTY|O_LARGEFILE
/dev/pts/3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With