-import qualified System.Posix.Process as P (getProcessID)
-getProcessID :: IO Int
-getProcessID = fromIntegral <$> P.getProcessID
-
+getProcessID :: ProcessHandle -> IO Int
+getProcessID p = fromIntegral . fromJust <$> getProcessID' p
+ where
+#if MIN_VERSION_process(1,6,3)
+ getProcessID' = System.Process.getPid
+#else
+ getProcessID' (ProcessHandle mh _ _) = do
+ p_ <- readMVar mh
+ case p_ of
+#ifdef mingw32_HOST_OS
+ OpenHandle h -> do
+ pid <- System.Win32.Process.getProcessId h
+ return $ Just pid
+#else
+ OpenHandle pid -> return $ Just pid
+#endif
+ _ -> return Nothing