Portability | non-portable (requires POSIX) |
---|---|
Stability | provisional |
Maintainer | libraries@haskell.org |
System.Posix.Process
Contents
Description
POSIX process support. See also the System.Cmd and System.Process modules in the process package.
- forkProcess :: IO() -> IOProcessID
- executeFile :: FilePath -> Bool -> [String] -> Maybe [(String, String)] -> IO a
- exitImmediately :: ExitCode -> IO()
- getProcessID :: IOProcessID
- getParentProcessID :: IOProcessID
- getProcessGroupID :: IOProcessGroupID
- createProcessGroup :: ProcessID -> IOProcessGroupID
- joinProcessGroup :: ProcessGroupID -> IO()
- setProcessGroupID :: ProcessID -> ProcessGroupID -> IO()
- createSession :: IOProcessGroupID
- dataProcessTimes = ProcessTimes {}
- getProcessTimes :: IOProcessTimes
- nice :: Int -> IO()
- getProcessPriority :: ProcessID -> IOInt
- getProcessGroupPriority :: ProcessGroupID -> IOInt
- getUserPriority :: UserID -> IOInt
- setProcessPriority :: ProcessID -> Int -> IO()
- setProcessGroupPriority :: ProcessGroupID -> Int -> IO()
- setUserPriority :: UserID -> Int -> IO()
- dataProcessStatus
- getProcessStatus :: Bool -> Bool -> ProcessID -> IO (MaybeProcessStatus)
- getAnyProcessStatus :: Bool -> Bool -> IO (Maybe (ProcessID, ProcessStatus))
- getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus))
Processes
Forking and executing
forkProcess :: IO() -> IOProcessIDSource
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.
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. Another example is the I/O manager thread: since the I/O manager isn't running in the child, attempting to do any Handle-based I/O will deadlock.
Using forkProcess
in order to do executeFile
is likely to work. Anything else: you're on your own.
Arguments
:: 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]
.
Exiting
exitImmediately :: ExitCode -> IO()Source
calls exitImmediately
status_exit
to terminate the process with the indicated exit status
. The operation never returns.
Process environment
getProcessID :: IOProcessIDSource
getProcessID
calls getpid
to obtain the ProcessID
for the current process.
getParentProcessID :: IOProcessIDSource
getProcessID
calls getppid
to obtain the ProcessID
for the parent of the current process.
getProcessGroupID :: IOProcessGroupIDSource
getProcessGroupID
calls getpgrp
to obtain the ProcessGroupID
for the current process.
Process groups
createProcessGroup :: ProcessID -> IOProcessGroupIDSource
calls createProcessGroup
pidsetpgid
to make process pid
a new process group leader.
joinProcessGroup :: ProcessGroupID -> IO()Source
calls joinProcessGroup
pgidsetpgid
to set the ProcessGroupID
of the current process to pgid
.
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO()Source
calls setProcessGroupID
pid pgidsetpgid
to set the ProcessGroupID
for process pid
to pgid
.
Sessions
createSession :: IOProcessGroupIDSource
createSession
calls setsid
to create a new session with the current process as session leader.
Process times
Constructors
ProcessTimes | |
Fields |
getProcessTimes :: IOProcessTimesSource
getProcessTimes
calls times
to obtain time-accounting information for the current process and its children.
Scheduling priority
getUserPriority :: UserID -> IOIntSource
Process status
getProcessStatus :: Bool -> Bool -> ProcessID -> IO (MaybeProcessStatus)Source
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))Source
calls getAnyProcessStatus
blk stoppedwaitpid
, returning
, the Just
(pid, tc)ProcessID
and ProcessStatus
for any child process if one 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.
getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus))Source
calls getGroupProcessStatus
blk stopped pgidwaitpid
, returning
, the Just
(pid, tc)ProcessID
and ProcessStatus
for any process in group pgid
if one 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.