From 564b2f836c7beb0776e4626263d8d5076af0e264 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 15 Aug 2024 10:06:54 -0700 Subject: [PATCH] Add `getPid` This allows fetching a process' ID without using `unsafeProcessHandle`. --- src/System/Process/Typed.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/System/Process/Typed.hs b/src/System/Process/Typed.hs index 42bd787..63dd714 100644 --- a/src/System/Process/Typed.hs +++ b/src/System/Process/Typed.hs @@ -109,6 +109,9 @@ module System.Process.Typed , checkExitCode , checkExitCodeSTM + -- ** Process ID + , getPid + -- ** Process streams , getStdin , getStdout @@ -121,6 +124,7 @@ module System.Process.Typed -- * Re-exports , ExitCode (..) , P.StdStream (..) + , P.Pid -- * Unsafe functions , unsafeProcessHandle @@ -641,6 +645,17 @@ checkExitCodeSTM p = do , eceStderr = L.empty } +-- | Returns the PID (process ID) of a subprocess. +-- +-- 'Nothing' is returned if the underlying 'P.ProcessHandle' was already closed. +-- Otherwise a PID is returned that remains valid as long as the handle is +-- open. The operating system may reuse the PID as soon as the last handle to +-- the process is closed. +-- +-- @since 0.2.12.0 +getPid :: Process stdin stdout stderr -> IO (Maybe P.Pid) +getPid = P.getPid . pHandle + -- | Internal clearStreams :: ProcessConfig stdin stdout stderr -> ProcessConfig () () () clearStreams pc = pc