Skip to content

Commit de19b4e

Browse files
9999yearstomjaguarpaw
authored andcommitted
Add getPid
This allows fetching a process' ID without using `unsafeProcessHandle`.
1 parent dd03392 commit de19b4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/System/Process/Typed.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ module System.Process.Typed
109109
, checkExitCode
110110
, checkExitCodeSTM
111111

112+
-- ** Process ID
113+
, getPid
114+
112115
-- ** Process streams
113116
, getStdin
114117
, getStdout
@@ -121,6 +124,7 @@ module System.Process.Typed
121124
-- * Re-exports
122125
, ExitCode (..)
123126
, P.StdStream (..)
127+
, P.Pid
124128

125129
-- * Unsafe functions
126130
, unsafeProcessHandle
@@ -641,6 +645,17 @@ checkExitCodeSTM p = do
641645
, eceStderr = L.empty
642646
}
643647

648+
-- | Returns the PID (process ID) of a subprocess.
649+
--
650+
-- 'Nothing' is returned if the underlying 'P.ProcessHandle' was already closed.
651+
-- Otherwise a PID is returned that remains valid as long as the handle is
652+
-- open. The operating system may reuse the PID as soon as the last handle to
653+
-- the process is closed.
654+
--
655+
-- @since 0.2.12.0
656+
getPid :: Process stdin stdout stderr -> IO (Maybe P.Pid)
657+
getPid = P.getPid . pHandle
658+
644659
-- | Internal
645660
clearStreams :: ProcessConfig stdin stdout stderr -> ProcessConfig () () ()
646661
clearStreams pc = pc

0 commit comments

Comments
 (0)