Path: utzoo!utgpu!water!watmath!clyde!rutgers!ukma!gatech!bloom-beacon!husc6!bbn!uwmcsd1!ig!agate!pasteur!sting.Berkeley.EDU!sarge From: sarge@sting.Berkeley.EDU (Steven Sargent) Newsgroups: comp.unix.wizards Subject: Re: To find out the names of open files in a process Message-ID: <535@pasteur.Berkeley.Edu> Date: 4 Feb 88 12:34:05 GMT References: <461@minya.UUCP> <2346@mandrill.CWRU.Edu> <339@tandem.UUCP> <7124@ncoast.UUCP> <1427@mips.mips.COM> Sender: news@pasteur.Berkeley.Edu Lines: 30 You can (with fair effort) discover the names of many (not all) disk files by fstat'ing the descriptor, then rooting around in directories to find the translation, then winding up to the root. (getwd(3), or pwd(1) for usg'ers, does something like this, but it depends on being able to start from "." This is somewhat more complicated). You can read the disk -- write a separate program that has readonly permissions for the disk -- being sure that you turn off close-on-exec flags for your fd's before running it. Note: - fails for non-disk files (e.g., pipes); restarting your process in mid-IPC is problematical, anyway; - fails if your process has created, then unlinked, a file (standard trick for creating temp files; on last close, the bits are reclaimed); You may not need read-disk permission (I'm too fuzzy right now to be sure), and just replicate what getwd does; in which case - fails if you don't have read permission on any of the intermediate directories. Salting away the names of files opened by open(2), &c. is ineffective since you can't know the names of files inherited by I/O redirection. I know of at least one implementation in which the full path name associated with u.u_cdir is maintained by the operating system (chdir(), &c. are never "fooled" by symbolic links). I suppose you could do the same thing with filenames ... but that way leads VMS. S.