Unix command that lists the files, sockets, and other file-descriptors that processes have open.
Questions tagged [lsof]
236 questions
3
votes
2 answers
Is there a perl function similar to lsof command in linux?
I have a shell script which archives log files based on the whether the process is running or not. If the log file is not used by the process then I archive it. Until now, I'm using lsof to get the log file being used but in future, I have decided…

cbrdy
- 792
- 1
- 8
- 27
2
votes
1 answer
Socket Descriptor Leak - lsof Can't Identify Protocol?
What is "can't identify protocol" when I run the command /usr/sbin/lsof -p 20085. The output of lsof is shown below
leak 20085 niki 3910u sock 0,5 2457507716 can't identify protocol
leak 20085 niki 3911u sock 0,5 …

Nikhil
- 576
- 1
- 11
- 31
2
votes
2 answers
Move file in Linux only when it's not in use by another process
Using the lsof command, I can determine whether a file is in use by some process, but I need to atomically check a file for use and move it only if unused. These files are in use by various other programs over which I have no control, so I can't use…

Jegschemesch
- 11,414
- 4
- 32
- 37
2
votes
3 answers
Could I list all running docker-compose files?
I was wondering if it would be possible to list all running docker-compose files with a bash function? Something like docker ps or docker container ls, but I want it to show the files only.
I got started with this - lsof | egrep 'REG|DIR' | awk…

kvelev
- 53
- 10
2
votes
2 answers
A flask website, when it delete a file (os.remove("abc.txt")), the file is removed but the space is not reclaimed
The program is a standard flask program, and it does some cleanup as part of the initialization. In the cleanup() procedure, using os.remove("abc.txt"), I noticed that the file is removed, but not reclaimed by the OS.
I use both "python website.py"…

Ben L
- 171
- 1
- 9
2
votes
2 answers
How to identify if file is still written or completed through linux script
We have one system which is generating files and I want to check which files out of many files are completed and also not been modified from past two minutes through a script and finally rename those.
This is what I tried but the result is not…

Rohit Shamdasani
- 31
- 7
2
votes
1 answer
lsof not giving o/p for bash built in read
When I do
find /
on a terminal and then do on another terminal
lsof -a -d 0-2 -c fin
I see o/p listed from execution of lsof command.
But when I do
echo hi ; read -t 30 hello
hi
on the same terminal ( as find) and do (on different terminal)
lsof…

Ankur Agarwal
- 23,692
- 41
- 137
- 208
2
votes
3 answers
How can you tell what files are currently open by any user?
I am trying to write a script or a piece of code to archive files, but I do not want to archive anything that is currently open. I need to find a way to determine what files in a directory are open. I want to use either Perl or a shell script, but…

Anthony
- 21
- 2
2
votes
1 answer
One command to kill a process using a specific port
For a project, I constantly need to find the process using a specific port and kill that process. I do this by:
lsof -i :portnumber
#read the pid
kill -9 pid
Since I do this a lot, I'm a bit bored to do so. So, I wonder if there is a way to kill a…

Yazgan
- 151
- 11
2
votes
1 answer
How to kill VueJS application running on localhost:8080 (MacOS)
My environment: MacOS Mojave
I created a VueJS application from their templates using
vue init pwa frontend
? Project name frontend
? Project short name: fewer than 12 characters to not be truncated on homescreens (default: same as name)
? Project…

Kevin Patrick
- 444
- 1
- 7
- 17
2
votes
0 answers
Linux process holding deleted file space
I have a process which is accessing a file. When I delete the file from the file system the space is not freed. when I do lsof | grep deleted I can see the process is holding the deleted file.
I tried to kill the process through kill -9 my…

Dev
- 3,885
- 10
- 39
- 65
2
votes
1 answer
Check if field in a output of command is empty or not
I am executing the command
lsof -nPs
The output of the command:
COMMAND PID TID USER FD TYPE DEVICE SIZE NODE NAME
systemd 1 root cwd DIR 253,0 4096 128…

Jay Joshi
- 1,402
- 1
- 13
- 32
2
votes
1 answer
Hang in poll system call
My program intermittently hanging in the poll call
strace output
poll([{fd=52, events=POLLIN}], 1, 250
<... poll resumed> ) = 0 (Timeout) <0.250281>
wait4(16953, 0x7f00cd24d90c, WNOHANG, NULL) = 0 <0.000019>
Looks like it is…

Parthiban Manoharan
- 307
- 2
- 12
2
votes
3 answers
formatting lsof output into parsable structure
I am trying to format lsof output in a more parsable way.
Background: since not all processes with open handles have thread IDs, the number of fields separated by whitespaces (blanks AFAIS) is not necessarily determined.
As output fields, I need the…

THX
- 553
- 2
- 8
- 18
2
votes
2 answers
Outgoing TCP port matches listening port
I've encountered a weird happenstance where the results of my
lsof | grep 40006
produced
java 29722 appsrv 54u IPv6 71135755 0t0 TCP localhost:40006->localhost:40006 (ESTABLISHED)
Generally I see
java …

user535674
- 23
- 3