getpid() or something similar
Thu, 22 May 2003 12:23:47 +0200
You can't guarantee that another process didn't happen to
write a file with just that name, pid or not.
> -----Original Message-----
> From: Peter Simons [mailto:firstname.lastname@example.org]
> Sent: Thursday, May 22, 2003 12:06 PM
> To: email@example.com
> Subject: Re: getpid() or something similar
> Simon Marlow writes:
> > Even using a ProcessID doesn't guarnatee uniqueness [...]
> Why not? If I use the file only temporarily (it is gone once the
> process terminates), something like /tmp/foo.<pid> will be unique, for
> all I can tell.
> > The right way to do this is to try to open it for writing, and try
> > a different name if the open fails.
> Unfortunately, this approach features a race condition because POSIX
> has no notion of mandatory file locking. I'd really rather avoid this,
> if I can.
> Is there no other way? And one that works across different compilers?
> Haskell-Cafe mailing list