Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- module System.Process.Typed
- forkProcess :: IO () -> IO ProcessID
- forkProcessWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ProcessID
- getProcessStatus :: Bool -> Bool -> ProcessID -> IO (Maybe ProcessStatus)
- getAnyProcessStatus :: Bool -> Bool -> IO (Maybe (ProcessID, ProcessStatus))
- getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus))
- exitImmediately :: ExitCode -> IO ()
- executeFile :: FilePath -> Bool -> [String] -> Maybe [(String, String)] -> IO a
- getProcessID :: IO ProcessID
- getParentProcessID :: IO ProcessID
- getProcessGroupID :: IO ProcessGroupID
- getProcessGroupIDOf :: ProcessID -> IO ProcessGroupID
- createProcessGroupFor :: ProcessID -> IO ProcessGroupID
- joinProcessGroup :: ProcessGroupID -> IO ()
- setProcessGroupIDOf :: ProcessID -> ProcessGroupID -> IO ()
- createSession :: IO ProcessGroupID
Spawning processes
High-level Haskell API
module System.Process.Typed
Low-level POSIX API
forkProcess :: IO () -> IO ProcessID #
forkProcess
corresponds to the POSIX fork
system call.
The IO
action passed as an argument is executed in the child process; no other
threads will be copied to the child process.
On success, forkProcess
returns the child's ProcessID
to the parent process;
in case of an error, an exception is thrown.
The exception masking state of the executed action is inherited
(c.f. forkIO
), see also forkProcessWithUnmask
(since: 2.7.0.0).
forkProcess
comes with a giant warning: since any other running
threads are not copied into the child process, it's easy to go wrong:
e.g. by accessing some shared resource that was held by another thread
in the parent.
forkProcessWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ProcessID #
Variant of forkProcess
in the style of forkIOWithUnmask
.
Since: unix-2.7.0.0
Waiting
getProcessStatus :: Bool -> Bool -> ProcessID -> IO (Maybe ProcessStatus) #
calls getProcessStatus
blk stopped pidwaitpid
, returning
, the Just
tcProcessStatus
for process pid
if it is
available, Nothing
otherwise. If blk
is False
, then
WNOHANG
is set in the options for waitpid
, otherwise not.
If stopped
is True
, then WUNTRACED
is set in the
options for waitpid
, otherwise not.
getAnyProcessStatus :: Bool -> Bool -> IO (Maybe (ProcessID, ProcessStatus)) #
calls getAnyProcessStatus
blk stoppedwaitpid
, returning
, the Just
(pid, tc)ProcessID
and ProcessStatus
for any
child process if a child process has exited, or Nothing
if
there are child processes but none have exited. If there are no
child processes, then getAnyProcessStatus
raises an
isDoesNotExistError
exception.
If blk
is False
, then WNOHANG
is set in the options for
waitpid
, otherwise not. If stopped
is True
, then
WUNTRACED
is set in the options for waitpid
, otherwise not.
getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus)) #
calls getGroupProcessStatus
blk stopped pgidwaitpid
,
returning
, the Just
(pid, tc)ProcessID
and ProcessStatus
for any process in group pgid
if one is available, or Nothing
if there are child processes but none have exited. If there are
no child processes, then getGroupProcessStatus
raises an
isDoesNotExistError
exception.
If blk
is False
, then WNOHANG
is set in the options for
waitpid
, otherwise not. If stopped
is True
, then
WUNTRACED
is set in the options for waitpid
, otherwise not.
Exiting the current process
exitImmediately :: ExitCode -> IO () #
calls exitImmediately
status_exit
to terminate the process
with the indicated exit status
.
The operation never returns.
Replacing the current process
:: FilePath | Command |
-> Bool | Search PATH? |
-> [String] | Arguments |
-> Maybe [(String, String)] | Environment |
-> IO a |
calls one of the
executeFile
cmd args envexecv*
family, depending on whether or not the current
PATH is to be searched for the command, and whether or not an
environment is provided to supersede the process's current
environment. The basename (leading directory names suppressed) of
the command is passed to execv*
as arg[0]
;
the argument list passed to executeFile
therefore
begins with arg[1]
.
Process info
getProcessID :: IO ProcessID #
getProcessID
calls getpid
to obtain the ProcessID
for
the current process.
getParentProcessID :: IO ProcessID #
getProcessID
calls getppid
to obtain the ProcessID
for
the parent of the current process.
Process groups
getProcessGroupID :: IO ProcessGroupID #
getProcessGroupID
calls getpgrp
to obtain the
ProcessGroupID
for the current process.
getProcessGroupIDOf :: ProcessID -> IO ProcessGroupID #
calls getProcessGroupIDOf
pidgetpgid
to obtain the
ProcessGroupID
for process pid
.
createProcessGroupFor :: ProcessID -> IO ProcessGroupID #
calls createProcessGroupFor
pidsetpgid
to make
process pid
a new process group leader.
joinProcessGroup :: ProcessGroupID -> IO () #
calls joinProcessGroup
pgidsetpgid
to set the
ProcessGroupID
of the current process to pgid
.
setProcessGroupIDOf :: ProcessID -> ProcessGroupID -> IO () #
calls setProcessGroupIDOf
pid pgidsetpgid
to set the
ProcessGroupIDOf
for process pid
to pgid
.
createSession :: IO ProcessGroupID #
createSession
calls setsid
to create a new session
with the current process as session leader.