Newsgroups: comp.unix.questions Path: utzoo!sq!lee From: lee@sq.sq.com (Liam R. E. Quin) Subject: Re: Lock Files From Shell Scripts Message-ID: <1989Nov10.013416.22125@sq.sq.com> Reply-To: lee@sq.com (Liam R. E. Quin) Organization: Unixsys (UK) Ltd References: <625@motbos.UUCP> <4963@macom1.UUCP> <3697@aplcen.apl.jhu.edu> <366@jupiter.iotek.UUCP> <25561EFF.29662@ateng.com> Date: Fri, 10 Nov 89 01:34:16 GMT In article <25561EFF.29662@ateng.com> chip@ateng.com (Chip Salzenberg) writes: >BZZT! You lose the System V Sweepstakes. > >SysV's "ln" will remove an existing file, rather like "cp" will. You have >to write your own "link" program. Those nice C News people did just that. True. This is why mkdir can be better... In my mail to the original poster, I suggested using mkdir in a loop. A file in the directory can contain the process' PID, and you can then do simple collision detection, using kill -0 to see if the other process is running. Obviously a file containing the Process ID can't be used as a semaphore, but the directory suffices, because only the process that created the directory can put the file there. It is harder to recover from the case of an empty directory, though. On the whole, it is probably simplest to write a "makelock" program, but one can't always do that (e.g. no C compiler). Lee -- Liam R. Quin, Unixsys (UK) Ltd lee@sq.com (whilst visiting Toronto from England) lee@anduk.co.uk (after Christmas)