How do I get exclusive access to a file?

How do I get exclusive access to a file?

Post by Mats Luthm » Tue, 20 Sep 1994 19:53:23



I want a program to be able to change the content of a file, when no other
(instance of the same) program can read (or write) it. One instance of the
program should be able to both read and update the file without
intervenience by another instance, which should be able to wait and read
and update when the first instance is ready.

Is there a portable (portable between UNIX systems, that is) to do this
without using other files as semaphores?
--
Mats Luthman, Sylog AB
Solna Torg 3, Box 1466
171 28 Solna, SWEDEN
phone: +46 8 730 00 15

 
 
 

How do I get exclusive access to a file?

Post by Ade Bark » Wed, 21 Sep 1994 01:27:45


: I want a program to be able to change the content of a file, when no other
: (instance of the same) program can read (or write) it. One instance of the
: program should be able to both read and update the file without
: intervenience by another instance, which should be able to wait and read
: and update when the first instance is ready.

: Is there a portable (portable between UNIX systems, that is) to do this
: without using other files as semaphores?

Try lockf() and fcntl() (flock structure). They're not that
portable (sysv-ish vs. BSD-ish), so you can use both of them
in #ifdef type codes.

-Ade Barkah

 
 
 

1. Kermit--Warning, problem getting exclusive access

Warning, problem getting exclusive access

I've been having a good deal of difficulty getting a CODEX modem hanging off an
IBM RS/6000 980 - AIX 3.2.5 configured to dial out. When first working on it, I
used kermit to attempt to connect and dial out. After going into kermit and typing
set modem hayes followed by set line /dev/tty35 I kept getting the message: Warning,
problem getting exclusive access.
Then I tried using cu to test the modem. Some uucp configuring was required as was
adding the -u -r switches to the getty entry in the inittab file. This followed by
changing an additional setting on the modem side permitted me to dial out of the
modem off of tty35 using cu. However, I keep getting the same warning referencing
exclusive access when I try to use kermit. I tried a couple things and I just dug up
info regarding uucp. I found a /etc/locks/LCK..tty35 file and thought that deleting this
may help?
Could someone enlighten me on what I'm doing wrong or what the details are if uucp
is creating some contention with kermit or if this warning has nothing to do with
uucp or ...

I'd greatly appreciate any feedback.


2. sound blaster 16 and cd

3. Obtaining exclusive access to a file

4. recommended modem under linux

5. Exclusive file access

6. problems with ESS1888 soundchip

7. Exclusive File access

8. Help: CDE XServers' ar1 & ar2 settings

9. help needed for exclusive file access

10. Exclusive Unix file system file write locks and Oracle and Veritas

11. exclusive access to scsi disk

12. exclusive device access

13. flock(), Named Pipes, and Exclusive Access