Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!rutgers!tut.cis.ohio-state.edu!cwjcc!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon S. Allbery) Newsgroups: comp.unix.wizards Subject: Re: Portable Message Queues Message-ID: <12560@ncoast.UUCP> Date: 14 Sep 88 23:05:56 GMT References: <7317@umn-cs.cs.umn.edu> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 30 As quoted from <7317@umn-cs.cs.umn.edu> by randy@umn-cs.cs.umn.edu (Randy Orrison): +--------------- | I expect that the best I can do will be just writing messages to a file and | using some form of file locking to ensure that the file doesn't get mangled. | | Is there a portable way of achieving file locking under all versions of Unix? | | I believe that using open(...O_CREAT|O_EXCL) on a lock file is the best there | is. Is this always true, and is there nothing better? +--------------- Is O_EXCL portable? I know System V has it, but possibly not BSD. The easiest and most portable way is non-obvious: while (link("datafile", "lockfile") != 0) (void) sleep(30); /* do your processing */ (void) unlink("lockfile"); After all, link() is available on all versions of *nix, and on all versions of *nix the destination pathname must not exist. (This is used in various places in System V-compatible (pre-fcntl-locking) programs, but in fact works as an advisory lock on all systems.) ++Brandon -- Brandon S. Allbery, uunet!marque!ncoast!allbery DELPHI: ALLBERY For comp.sources.misc send mail to ncoast!sources-misc "Don't discount flying pigs before you have good air defense." -- jvh@clinet.FI