home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:3135 comp.unix.programmer:3915
- Newsgroups: comp.unix.shell,comp.unix.programmer
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!machine!chinet!les
- From: les@chinet.chi.il.us (Leslie Mikesell)
- Subject: Re: file locking in shell scripts
- Message-ID: <1992Jul25.213443.1900@chinet.chi.il.us>
- Date: Sat, 25 Jul 1992 21:34:43 GMT
- References: <1992Jul23.124327.20843@cv.ruu.nl>
- Organization: Chinet - Public Access UNIX
- Lines: 20
-
- In article <1992Jul23.124327.20843@cv.ruu.nl> rvloon@cv.ruu.nl (Ronald van Loon) writes:
- >Somewhere on our system is a log-file. This logfile is used to gather
- >statistical information. However, it is possible that people write to the file
- >at the same time, thus resulting in either the merge of the input-streams or
- >total garbage in the file.
-
- >How can I - within a shell script - lock the file exclusive for writing ? If
- >that's not possible, what do I need to use to do so from C, for example ?
-
- On unix systems it is pretty common to just ignore this issue for logfiles
- where the messages are short. If you open a file in append mode, every
- write() is positioned at the current end-of-file, so messages that
- are generated in a single write() will be kept intact. It can be
- tricky to get a shell script to output a message in a single write()
- but accumulating the string into a variable with an "echo "$VAR" >>file"
- to dump it should work. As long as the other users are using append
- mode (and you aren't going over NFS) the messages should stay intact.
-
- Les Mikesell
- les@chinet.chi.il.us
-