getpid() or something similar

Please pardon me if it turns out I'm just blind, but is there any function I can use to get some "unique" information to use for temporary file names and the like? A function that will tell me my process ID, for instance? I looked through Hugs and GHC, yet couldn't find anything but Data.Unique, and that looks like big-time overkill for the purpose. Any pointers are appreciated! Peter

In GHC in the Posix module, there's GetProcessID: Prelude> :m Posix Prelude Posix> getProcessID Prelude Posix> it 16151 -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On 22 May 2003, Peter Simons wrote:
Please pardon me if it turns out I'm just blind, but is there any function I can use to get some "unique" information to use for temporary file names and the like? A function that will tell me my process ID, for instance?
I looked through Hugs and GHC, yet couldn't find anything but Data.Unique, and that looks like big-time overkill for the purpose.
Any pointers are appreciated!
Peter
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hal Daume writes:
In GHC in the Posix module, there's GetProcessID:
Thanks for the pointer! Unfortunately, this is a GHC-only solution, which is really annoying in my case because the software is completely compiler-independent, and I don't want to restrict it to GHC because I need it to determine a unique file name for a temporary file! Is there no other way? I cannot be the first person ever to need a temporary file, can I? Surely there must be some portable way, too? Peter

Heres a couple of useful functions for creating a temporary file. getUniqueName creates a unique filename and atomicWrite uses it to atomically update a file on the filesystem by writing to a temporary file and renaming it over the target. John getUniqueName :: IO String getUniqueName = do id <- getProcessID u <- newUnique n <- liftM nodeName getSystemID t <- epochTime return $ n ++ "." ++ show id ++ "." ++ show t ++ "." ++ show (hashUnique u) atomicWrite :: String -> (Handle -> IO a) -> IO a atomicWrite fn action = do n <- getUniqueName let tn = fn ++ "." ++ n v <- E.bracket (openFile tn WriteMode) hClose action rename tn fn return v On Thu, May 22, 2003 at 01:02:57AM +0200, Peter Simons wrote:
Please pardon me if it turns out I'm just blind, but is there any function I can use to get some "unique" information to use for temporary file names and the like? A function that will tell me my process ID, for instance?
I looked through Hugs and GHC, yet couldn't find anything but Data.Unique, and that looks like big-time overkill for the purpose.
Any pointers are appreciated!
-- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@foo.net ---------------------------------------------------------------------------
participants (3)
-
Hal Daume III
-
John Meacham
-
Peter Simons