I have 30 instances of a process running on a server and want to log open files for each process for analysis.
I ran the following command:
* ps auwwx | grep PROG_NAME | awk '{print $2}' | xargs lsof -p | less
It complaints that, "lsof: status error on : No such file or directory"
However, if I run lsof -p < pid >
it gives me the list of open files for that process . How can I get a list of all open files for all 30 instances of the process on a FreeBSD machine.
Moreover, I do not want the shared libraries to be listed. If I do -d "^txt"
it isn't showing some other db files which I want to be shown. Is there any other way to grep out the .so files?
“lsof” stands for List Open Files. It is a Linux utility for listing down all the open files of a system. This command can be combined with different parameters to modify its output as desired.
The lsof command stands for LiSt Open Files and shows open files and which process uses them. Since Linux sees every object as a file, such as devices, directories, etc., unidentified open files prevent users from modifying them. Additionally, the sheer number of files makes it difficult to find malicious processes.
lsof stands for List Open Files. It is easy to remember lsof command if you think of it as “ls + of”, where ls stands for list, and of stands for open files. It is a command line utility which is used to list the information about the files that are opened by various processes.
To find out the list of files opened by parent process Id lsof command is used with the option -R.
The lsof -p
option takes a comma-separated list of PIDs. The way you're using xargs
will pass the pids as separate arguments leading some to be interpreted as filenames.
Try lsof -p $(your grep | tr '\012' ,)
That's going to have a trailing comma, I'm not sure if lsof
will care but you could sed
it off if necessary.
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