Haskell Hierarchical Libraries (unix package)ContentsIndex
System.Posix.Process
Portabilitynon-portable (requires POSIX)
Stabilityprovisional
Maintainerlibraries@haskell.org
Contents
Processes
Forking and executing
Exiting
Process environment
Process groups
Sessions
Process times
Scheduling priority
Process status
Description
POSIX process support
Synopsis
forkProcess :: IO () -> IO ProcessID
executeFile :: FilePath -> Bool -> [String] -> Maybe [(String, String)] -> IO ()
exitImmediately :: ExitCode -> IO ()
getProcessID :: IO ProcessID
getParentProcessID :: IO ProcessID
getProcessGroupID :: IO ProcessGroupID
createProcessGroup :: ProcessID -> IO ProcessGroupID
joinProcessGroup :: ProcessGroupID -> IO ()
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO ()
createSession :: IO ProcessGroupID
data ProcessTimes = ProcessTimes {
elapsedTime :: ClockTick
userTime :: ClockTick
systemTime :: ClockTick
childUserTime :: ClockTick
childSystemTime :: ClockTick
}
getProcessTimes :: IO ProcessTimes
nice :: Int -> IO ()
getProcessPriority :: ProcessID -> IO Int
getProcessGroupPriority :: ProcessGroupID -> IO Int
getUserPriority :: UserID -> IO Int
setProcessPriority :: ProcessID -> Int -> IO ()
setProcessGroupPriority :: ProcessGroupID -> Int -> IO ()
setUserPriority :: UserID -> Int -> IO ()
data ProcessStatus
= Exited ExitCode
| Terminated Signal
| Stopped Signal
getProcessStatus :: Bool -> Bool -> ProcessID -> IO (Maybe ProcessStatus)
getAnyProcessStatus :: Bool -> Bool -> IO (Maybe (ProcessID, ProcessStatus))
getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus))
Processes
Forking and executing
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.
executeFile :: FilePath -> Bool -> [String] -> Maybe [(String, String)] -> IO ()
literal>executeFile cmd args env</literal calls one of the function>execv*</function 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 function>execv*</function> as <varname>arg[0]</varname; the argument list passed to function>executeFile</function therefore begins with varname>arg[1]</varname.
Exiting
exitImmediately :: ExitCode -> IO ()
literal>exitImmediately status</literal> calls <function>&lowbar;exit</function to terminate the process with the indicated exit literal>status</literal. The operation never returns.
Process environment
getProcessID :: IO ProcessID
function>getProcessID</function> calls <function>getpid</function to obtain the literal>ProcessID</literal for the current process.
getParentProcessID :: IO ProcessID
function>getProcessID</function> calls <function>getppid</function> to obtain the <literal>ProcessID</literal for the parent of the current process.
getProcessGroupID :: IO ProcessGroupID
function>getProcessGroupID</function> calls <function>getpgrp</function to obtain the literal>ProcessGroupID</literal for the current process.
Process groups
createProcessGroup :: ProcessID -> IO ProcessGroupID
literal>createProcessGroup pid</literal> calls <function>setpgid</function to make process literal>pid</literal a new process group leader.
joinProcessGroup :: ProcessGroupID -> IO ()
literal>joinProcessGroup pgid</literal> calls <function>setpgid</function to set the literal>ProcessGroupID</literal> of the current process to <literal>pgid</literal.
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO ()
literal>setProcessGroupID pid pgid</literal> calls <function>setpgid</function to set the literal>ProcessGroupID</literal> for process <literal>pid</literal> to <literal>pgid</literal.
Sessions
createSession :: IO ProcessGroupID
function>createSession</function> calls <function>setsid</function to create a new session with the current process as session leader.
Process times
data ProcessTimes
Constructors
ProcessTimes
elapsedTime :: ClockTick
userTime :: ClockTick
systemTime :: ClockTick
childUserTime :: ClockTick
childSystemTime :: ClockTick
getProcessTimes :: IO ProcessTimes
function>getProcessTimes</function> calls <function>times</function to obtain time-accounting information for the current process and its children.
Scheduling priority
nice :: Int -> IO ()
getProcessPriority :: ProcessID -> IO Int
getProcessGroupPriority :: ProcessGroupID -> IO Int
getUserPriority :: UserID -> IO Int
setProcessPriority :: ProcessID -> Int -> IO ()
setProcessGroupPriority :: ProcessGroupID -> Int -> IO ()
setUserPriority :: UserID -> Int -> IO ()
Process status
data ProcessStatus
Constructors
Exited ExitCode
Terminated Signal
Stopped Signal
show/hide Instances
getProcessStatus :: Bool -> Bool -> ProcessID -> IO (Maybe ProcessStatus)
literal>getProcessStatus blk stopped pid</literal> calls <function>waitpid</function, returning literal>Just tc</literal>, the <literal>ProcessStatus</literal> for process <literal>pid</literal if it is available, literal>Nothing</literal> otherwise. If <literal>blk</literal> is <literal>False</literal, then literal>WNOHANG</literal> is set in the options for <function>waitpid</function, otherwise not. If literal>stopped</literal> is <literal>True</literal>, then <literal>WUNTRACED</literal is set in the options for function>waitpid</function, otherwise not.
getAnyProcessStatus :: Bool -> Bool -> IO (Maybe (ProcessID, ProcessStatus))
literal>getAnyProcessStatus blk stopped</literal> calls <function>waitpid</function, returning literal>Just (pid, tc)</literal>, the <literal>ProcessID</literal> and <literal>ProcessStatus</literal for any child process if one is available, literal>Nothing</literal otherwise. If literal>blk</literal> is <literal>False</literal>, then <literal>WNOHANG</literal is set in the options for function>waitpid</function>, otherwise not. If <literal>stopped</literal> is <literal>True</literal, then literal>WUNTRACED</literal> is set in the options for <function>waitpid</function, otherwise not.
getGroupProcessStatus :: Bool -> Bool -> ProcessGroupID -> IO (Maybe (ProcessID, ProcessStatus))
literal>getGroupProcessStatus blk stopped pgid</literal> calls <function>waitpid</function, returning literal>Just (pid, tc)</literal>, the <literal>ProcessID</literal and literal>ProcessStatus</literal> for any process in group <literal>pgid</literal if one is available, literal>Nothing</literal> otherwise. If <literal>blk</literal> is <literal>False</literal, then literal>WNOHANG</literal> is set in the options for <function>waitpid</function, otherwise not. If literal>stopped</literal> is <literal>True</literal>, then <literal>WUNTRACED</literal is set in the options for function>waitpid</function, otherwise not.
Produced by Haddock version 0.7