Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!phoenix.Princeton.EDU!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.programmer Subject: Re: Checking if a process opened a file Message-ID: <7794@idunno.Princeton.EDU> Date: 2 Apr 91 14:39:16 GMT References: Sender: news@idunno.Princeton.EDU Lines: 37 In article it1@Isis.MsState.Edu (Tim Tsai) writes: > Is it possible to check if a process (possibly from another machine >via NFS) opened a file for reading/writing? I've mucked with the >select() call, but the call always returns with the value 1. What is >an "exceptional condition"? Here's a sketch of what I've attempted >(with error checking, etc removed): > > infile = open ( filename, O_RDONLY ); > FD_ZERO ( &fdset ); > FD_SET ( infile, &fdset ); > for (;;) > { > result = select ( ulimit(), 0, 0, &fdset, 0 ); > printf ("exceptional condition on %s, result = %d\n", filename, > result); > } select() is used generally to determine whether a file descriptor is ready for reading from, or writing to. In the case of a "normal" file (i.e not a socket or tty or something), reads and writes generally do not have a chance of blocking indefinitely, like they might on a tty, because there's no chance of 'more' information appearing in the file. An example of an "exceptional" condition would be out of band data on a socket. Again, something you are not really interested in here. There is a command ofiles to determine who has a given file open, but I'm not sure that this works across NFS -- your best bet might be to either set up some communication with any other process that wants to open a file (via sockets) or establish your own protocol for determining that another process wants to access this file. -Kartik -- internet# find . -name core -exec cat {} \; |& tee /dev/tty* subbarao@phoenix.Princeton.EDU -| Internet kartik@silvertone.Princeton.EDU (NeXT mail) SUBBARAO@PUCC.BITNET - Bitnet