Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify the files opened a particular process on linux

Tags:

linux

process

pid

I need a script to identify the files opened a particular process on linux

To identify fd :

>cd /proc/<PID>/fd; ls |wc –l  

I expect to see a list of numbers which is the list of files descriptors' number using in the process. Please show me how to see all the files using in that process. Thanks.

like image 857
aladine Avatar asked Apr 21 '10 09:04

aladine


People also ask

How do you find the list of open files by a specific process in Linux?

The Linux lsof command lists information about files that are open by processes running on the system. The lsof command is an acronym for, “list of open files.” In this article I'll share some lsof command examples.

How do you check which files a process is using Linux?

Lsof is used on a file system to identify who is using any files on that file system. You can run lsof command on Linux filesystem and the output identifies the owner and process information for processes using the file as shown in the following output.

Which command is used to identify list of open files by a process?

The open source lsof command is also useful for providing information about files opened by processes, and files opened under specific user accounts.

How do you check if a file is open by another process Linux?

The command lsof -t filename shows the IDs of all processes that have the particular file opened. lsof -t filename | wc -w gives you the number of processes currently accessing the file.


1 Answers

lsof -p <pid number here> | wc -l

if you don't have lsof, you can do roughly the same using just /proc

eg

$ pid=1825
$ ls -1 /proc/$pid/fd/*
$ awk '!/\[/&&$6{_[$6]++}END{for(i in _)print i}' /proc/$pid/maps
like image 74
ghostdog74 Avatar answered Sep 21 '22 14:09

ghostdog74