+getCurrentProcessID = fromIntegral <$> System.Win32.Process.getCurrentProcessId
+#else
+getCurrentProcessID = fromIntegral <$> System.Posix.Process.getProcessID
+#endif
+
+getProcessID :: ProcessHandle -> IO Int
+getProcessID p = fromIntegral . fromJust <$> getProcessID' p
+ where
+#if MIN_VERSION_process(1,6,3)
+ getProcessID' = System.Process.getPid
+#else
+#if MIN_VERSION_process(1,6,0)
+ getProcessID' (ProcessHandle mh _ _) = do
+#else
+ getProcessID' (ProcessHandle mh _) = do
+#endif
+ 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
+#endif