Re: Is a file used by another application?
Re: Is a file used by another application?
- Subject: Re: Is a file used by another application?
- From: Graham Lee <email@hidden>
- Date: Sun, 19 Jan 2003 21:25:36 +0000
- Organization: University of Oxford
Tomas Zahradnicky wrote:
Hi,
is there a way in Cocoa to know if a given file is used by another
application or process? I think this would be some kind of equivalent
of the lsof shell command.
Unfortunately NO.
Lsof traversers kernel structures in a very unhealthy way. If you want
similiar functionality either parse results of lsof or grab it from lsof
source.
-Tomas
OK so it's not Cocoa, but couldn't you just use the standard UNIX
flock()? That would at least tell you whether or not another program
had previously locked the file. OK it's not perfect because you have to
rely on the other programmer being competent enough to flock() a file
that can be accessed by other processes, but it's a start...It may be
enough if you're the person who wrote the other program though :-)
#include <sys/file.h>
...
int filedesc;
if(flock(filedesc,LOCK_EX|LOCK_NB)!=0)
{
/*Failure - other program has locked file*/
}
else
{
/*Success - file is exclusively writable by me*/
}
Graham
--
Graham Lee, Wadham College, OX1 3PN.
Please send any attached documents as PDF, PostScript, HTML, RTF or
(better) plain text. If you send me a PowerPoint presentation I won't
read it. I will send you a reply on a Z88 EPROM card.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.