Return to BSD News archive
Xref: sserve comp.sys.hp:18995 comp.unix.sys5.misc:60 comp.unix.bsd:8147 Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!tamsun.tamu.edu!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!ugle.unit.no!nuug!ifi.uio.no!gjermund From: gjermund@ifi.uio.no (Gjermund S|rseth) Newsgroups: comp.sys.hp,comp.unix.sys5.misc,comp.unix.bsd Subject: Re: Flock in HP-UX / SV based systems Message-ID: <1992Nov24.221036.9811@ifi.uio.no> Date: 24 Nov 92 22:10:36 GMT References: <1992Nov24.101411.3211@hp9000.csc.cuhk.hk> Sender: gjermund@ifi.uio.no (Nicknack) Organization: Dept. of Informatics, University of Oslo, Norway Lines: 38 Nntp-Posting-Host: allfar.ifi.uio.no Originator: gjermund@allfar.ifi.uio.no In article <1992Nov24.101411.3211@hp9000.csc.cuhk.hk>, a866700@hp9000.csc.cuhk.hk (Wong Siu To) writes: > > Could anyone pls tell me how can I use flock(2) on HP-UX 8.07 or other > System V based systems ? It seems that HP-UX doesn't get this function > call, plus the header <sys/file.h>. > > I want to port a program runs on Ultrix, which uses flock. How can I > get it run by modifying the call to flock ? The BSD system call flock() sets or removes shared and exclusive locks (sometimes called read and write locks) on open files. You need to replace the calls to flock() by appropriate calls to fcntl(). Example, to set an exclusive (write) lock (and block until action is possible): Using BSD-flock(): flock(fd, LOCK_EX); Using fcntl(): struct flock fl = { F_WRLCK, SEEK_SET, 0, 0, 0 }; fcntl(fd, F_SETLKW, &fl); Study the man-pages for fcntl(). Hope this helps. +--------------------------------------------------------------------------+ |Gjermund Sorseth University of Oslo Net: gjermund@ifi.uio.no | |cs grad student Oslo, Norway 59 58' N, 10 43' E | | | +--------------------------------------------------------------------------+