RE: getpid() or something similar

You can't guarantee that another process didn't happen to write a file with just that name, pid or not. Markus
-----Original Message----- From: Peter Simons [mailto:simons@cryp.to] Sent: Thursday, May 22, 2003 12:06 PM To: haskell-cafe@haskell.org 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?
Peter
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (1)
-
Markus.Schnell@infineon.com