diff --git a/src/System/Process/Typed.hs b/src/System/Process/Typed.hs index 42bd787..c2e4282 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 @@ -138,6 +141,7 @@ import Control.Concurrent (threadDelay) import Control.Concurrent.Async (asyncWithUnmask, cancel, waitCatch) import Control.Concurrent.STM (newEmptyTMVarIO, atomically, putTMVar, TMVar, readTMVar, tryReadTMVar, STM, tryPutTMVar, throwSTM, catchSTM) import System.Exit (ExitCode (ExitSuccess, ExitFailure)) +import System.Posix.Types (ProcessID) import System.Process.Typed.Internal import qualified Data.ByteString.Lazy as L import GHC.RTS.Flags (getConcFlags, ctxtSwitchTime) @@ -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 ProcessID) +getPid = P.getPid . pHandle + -- | Internal clearStreams :: ProcessConfig stdin stdout stderr -> ProcessConfig () () () clearStreams pc = pc