How to tell if their are open file handles when exiting a process?

How to tell if their are open file handles when exiting a process?

Post by Thaddeus L Olczy » Sun, 28 Apr 2002 18:08:18



I'm exiting a process, and I would like to know if I closed all
the file handles ( in particular, I'm playing with pipes ).
Is there a system call or something which I can use to list the open
file handles to know for sure?
How about a debugging tool like mpatrol?
TIA
 
 
 

How to tell if their are open file handles when exiting a process?

Post by Kasper Dupon » Sun, 28 Apr 2002 20:42:12



> I'm exiting a process, and I would like to know if I closed all
> the file handles ( in particular, I'm playing with pipes ).
> Is there a system call or something which I can use to list the open
> file handles to know for sure?
> How about a debugging tool like mpatrol?
> TIA

You can get a directory listning of /proc/self/fd (or
/dev/fd which might even work on some other architectures.)

--
Kasper Dupont -- der bruger for meget tid p? usenet.


 
 
 

How to tell if their are open file handles when exiting a process?

Post by Thaddeus L Olczy » Tue, 30 Apr 2002 07:40:44


On Sat, 27 Apr 2002 13:42:12 +0200, Kasper Dupont



>> I'm exiting a process, and I would like to know if I closed all
>> the file handles ( in particular, I'm playing with pipes ).
>> Is there a system call or something which I can use to list the open
>> file handles to know for sure?
>> How about a debugging tool like mpatrol?
>> TIA

>You can get a directory listning of /proc/self/fd (or

Hmmm. Interesting. I knew that the /proc system was a "virtual"
filesystem, but I didn't know that it was possible to create entries
in /proc on a per process level. Checking the entries in /proc/self,
it is.
Suprise. ( Never having looked at /proc internals before. )
Quote:>/dev/fd which might even work on some other architectures.)

Aren't there actual inodes pointing to virtual things on the disk?
If so it's hard to see how this could be done.
 
 
 

How to tell if their are open file handles when exiting a process?

Post by Kasper Dupon » Tue, 30 Apr 2002 17:06:12



> On Sat, 27 Apr 2002 13:42:12 +0200, Kasper Dupont

> >You can get a directory listning of /proc/self/fd (or
> Hmmm. Interesting. I knew that the /proc system was a "virtual"
> filesystem, but I didn't know that it was possible to create entries
> in /proc on a per process level. Checking the entries in /proc/self,
> it is.

/proc contains one directory per process. (named by it's pid)
The special entry self is a symlink to the pid of the process
doing the lookup.

Quote:> Suprise. ( Never having looked at /proc internals before. )
> >/dev/fd which might even work on some other architectures.)
> Aren't there actual inodes pointing to virtual things on the disk?
> If so it's hard to see how this could be done.

On some systems /dev/fd is a directory, on Linux it is merely
a symlink to /proc/self/fd. So you can access /dev/fd/0 for
stdin, /dev/fd/1 for stdout, and so on. There are differences
between the semantics of /dev/fd on different systems. You
cannot assume that a entry in /dev/fd is a garantee that the
file is open. But getting a listning of /dev/fd and then
verifying that each entry actually is an open file would work
on many systems. (For those Linux systems without /dev/fd you
would still have to use /proc/self/fd.)

--
Kasper Dupont -- der bruger for meget tid p? usenet.

 
 
 

1. How can a process tell if another process has a file open?

Is there a way to tell if another process has a file open? I'm running two
processes which open the same file (call them process A and process B).
Process A creates the file, writes to it, and closes it. Process B is
monitoring the directory where process A will be creating files. When it
detects a file, it will open it, read and process it, close it, and remove
the file.

My problem is that I have no control over process A. This process is
developed by another organization here at NCR. I can only control
process B. Is there any way that process B can detect if process A (or
any other process) has the file open?

2. What are the downsides of LinuxPPC 2000?

3. How do I tell what process has a file open?

4. MkLinux and Darwin

5. How to tell which process(es) have a given file/inode open under SVr4?

6. Routing Question

7. System call tell how many files open in a process

8. subshell puzzle

9. Tell if another process open a file

10. How to tell if a file is open by another process?

11. How can you tell if a streams file is opened by another process?

12. ksh file open with variable file handle

13. map a process open file to a open socket ?