From: =?ISO-8859-1?Q?Une_B=E9vue?= on
Brian Candler <b.candler(a)pobox.com> wrote:

> > The traditional Unix utilities to solve this problem are "lsof" and
> > "fuser". I don't know if OSX has either of these as standard, but they
> > are probably available as ports.
>
> Or it might be "fstat", given that OSX is BSD-derived.
> http://netbsd.gw.com/cgi-bin/man-cgi?fstat++NetBSD-4.0

seems fstat doesn't exists on OS X :

zsh-% which fstat
fstat not found

however lsof and fuser does exists.

then i did some experiment ))

assuming the file is opened in a text editor i get :
zsh-% fuser -fu /Users/yt/dev/Signature/signatures.txt
/Users/yt/dev/Signature/signatures.txt:

or, with lsof :
zsh-% lsof /Users/yt/dev/Signature/signatures.txt
zsh-%


i get the correct answer when the file is selected by the Finder :
with fuser :
zsh-% fuser -fu /Users/yt/dev/Signature/signatures.txt
/Users/yt/dev/Signature/signatures.txt: 106(yt)

and, with lsof :
zsh-% lsof /Users/yt/dev/Signature/signatures.txt
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Finder 106 yt 14r REG 14,2 3082 7364119
/Users/yt/dev/Signature/signatures.txt

then, i think, may be i'm wrong, that any text editor open a file show
it and close it afterwards even the file is still visible in that text
editor where the Finder lock the file when it is selected.

then lsof nor fuser are no help in my case because i want to avoid
opening a file under editing...

--
� L'essence m�me du g�nie, c'est de mettre en pratique
les id�es les plus simples. �
(Charles Peguy)
From: Brian Candler on
Une Bévue wrote:
> then, i think, may be i'm wrong, that any text editor open a file show
> it and close it afterwards even the file is still visible in that text
> editor where the Finder lock the file when it is selected.

That sounds quite likely.

> then lsof nor fuser are no help in my case because i want to avoid
> opening a file under editing...

Then the solution depends on your editor.

For example, under Linux, if I create file foo then do "vi foo", lsof
and fuser show that foo is not open. However, a lockfile ".foo.swp" is
created, and this is what prevents another vi instance from editing it.

If I edit the file in joe, then nothing is changed until I start typing
into that window. Then it creates ".#foo" which is a symlink to the user
and the pid of the joe instance. That is: the lock is only created when
I start to modify the buffer.

So there doesn't appear to be a universal way of handling this, although
perhaps Apple prescribe a standard way for applications to adhere to.

Useful command to see if any new dot-files are created:

ls -lArt | grep ^\\.

(newest files appear at the end of the list)

HTH,

Brian.
--
Posted via http://www.ruby-forum.com/.

From: =?ISO-8859-1?Q?Une_B=E9vue?= on
Brian Candler <b.candler(a)pobox.com> wrote:

>
> So there doesn't appear to be a universal way of handling this, although
> perhaps Apple prescribe a standard way for applications to adhere to.

Apple recommandation are, afaik, * no test * but raise an exception if
an error occurs...
--
� L'essence m�me du g�nie, c'est de mettre en pratique
les id�es les plus simples. �
(Charles Peguy)