Questions tagged [open-files]

Dealing with files that are currently opened in a program

Use this tag for questions about open file descriptors: listing them, reacting to events, etc.

For questions about selecting which program will be used when opening a file, see .

Useful tools

  • fuser: list the processes that have a given file open
  • lsof: list open files of processes
  • /proc: on many Unix variants, contains a directory for each process
139 questions
167
votes
3 answers

Why is number of open files limited in Linux?

Right now, I know how to: find open files limit per process: ulimit -n count all opened files by all processes: lsof | wc -l get maximum allowed number of open files: cat /proc/sys/fs/file-max My question is: Why is there a limit of open files in…
xanpeng
  • 5,595
  • 7
  • 24
  • 20
161
votes
4 answers

Find and remove large files that are open but have been deleted

How does one find large files that have been deleted but are still open in an application? How can one remove such a file, even though a process has it open? The situation is that we are running a process that is filling up a log file at a terrific…
dotancohen
  • 15,494
  • 26
  • 80
  • 116
132
votes
8 answers

How do I find out which processes are preventing unmounting of a device?

Sometimes, I would like to unmount a usb device with umount /run/media/theDrive, but I get a drive is busy error. How do I find out which processes or programs are accessing the device?
Stefan
  • 24,830
  • 40
  • 98
  • 126
118
votes
2 answers

ulimit: difference between hard and soft limits

What is the difference between hard and soft limits in ulimit? For number of open files, I have a soft limit of 1024 and a hard limit of 10240. It is possible to run programs opening more than 1024 files. What is the soft limit for?
daniel kullmann
  • 9,427
  • 11
  • 38
  • 45
76
votes
8 answers

Who's got the other end of this unix socketpair?

I want to determine which process has the other end of a UNIX socket. Specifically, I'm asking about one that was created with socketpair(), though the problem is the same for any UNIX socket. I have a program parent which creates a…
Jonathon Reinhart
  • 1,821
  • 1
  • 16
  • 20
70
votes
5 answers

How to list the open file descriptors (and the files they refer to) in my current bash session

I am running in an interactive bash session. I have created some file descriptors, using exec, and I would like to list what is the current status of my bash session. Is there a way to list the currently open file descriptors?
blueFast
  • 1,168
  • 2
  • 11
  • 15
62
votes
1 answer

How do I monitor opened files of a process in realtime?

I know I can view the open files of a process using lsof at that moment in time on my Linux machine. However, a process can open, alter and close a file so quickly that I won't be able to see it when monitoring it using standard shell scripting…
gertvdijk
  • 13,459
  • 7
  • 45
  • 59
57
votes
2 answers

Why does process substitution result in a file called /dev/fd/63 which is a pipe?

I am trying to understand named pipes in the context of this particular example. I type <(ls -l) in my terminal and get the output as, bash: /dev/fd/63: Permission denied. If I type cat <(ls -l), I could see the directory contents. If I replace the…
Ramesh
  • 38,687
  • 43
  • 140
  • 215
45
votes
5 answers

How do I tell a script to wait for a process to start accepting requests on a port?

I need a command that will wait for a process to start accepting requests on a specific port. Is there something in linux that does that? while (checkAlive -host localhost -port 13000 == false) do some waiting ...
Will
  • 593
  • 1
  • 4
  • 6
45
votes
4 answers

How do I "cat and follow" a file?

A file is being sequentially downloaded by wget. If I start unpacking it with cat myfile.tar.bz2 | tar -xj, it may unpack correctly or fail with "Unexpected EOF", depending on what is faster. How to "cat and follow" a file, i.e. output content of…
Vi.
  • 5,528
  • 7
  • 34
  • 68
40
votes
2 answers

/proc/PID/fd/X link number

In Linux, in /proc/PID/fd/X, the links for file descriptors that are pipes or sockets have a number, like: l-wx------ 1 user user 64 Mar 24 00:05 1 -> pipe:[6839] l-wx------ 1 user user 64 Mar 24 00:05 2 -> pipe:[6839] lrwx------ 1 user user 64 Mar…
Thanatos
  • 897
  • 1
  • 6
  • 17
38
votes
7 answers

Best way to free disk space from deleted files that are held open

Hi I have many files that have been deleted but for some reason the disk space associated with the deleted files is unable to be utilized until I explicitly kill the process for the file taking the disk space $ lsof /tmp/ COMMAND PID USER FD …
BryanK
  • 783
  • 1
  • 7
  • 12
35
votes
2 answers

How to find out the file offset of an opened file?

My problem is that with lsof -p pid I can find out the list of opened file of a process whose process id is pid. But is there a way to find out the file offset of each accessed file ? Please give me some suggestions ?
Ta Thanh Dinh
  • 453
  • 1
  • 4
  • 5
35
votes
5 answers

How can same fd in different processes point to the same file?

Say I have process 1 and process 2. Both have a file descriptor corresponding to the integer 4. In each process however the file descriptor 4 points to a totally different file in the Open File Table of the kernel: How is that possible? Isn't a…
Pithikos
  • 3,214
  • 4
  • 23
  • 27
31
votes
4 answers

How to switch to the directory listing from file view in vim?

I have opened a dir vim some/dir. I can navigate within the tree, yet once I opened a file I wonder, how do I close the file view in order to go back to the directory listing to navigate to another file. :wq is no option, as it closes the whole vim…
k0pernikus
  • 14,853
  • 21
  • 58
  • 79
1
2 3
9 10