Skip to content
Snippets Groups Projects
Commit ff80c44c authored by Favonia's avatar Favonia Committed by Simon Marlow
Browse files

Change the POSIX process group API. (trac #5167)

Make it possible to query the process group of an existing
process (through 'getProcessGroupIDOf') and try to make
function names more consistent. Here is the full list of
API changes in System.Posix.Process in this patch:

getProcessGroupID     => same
getProcessGroupIDOf   => new
createProcessGroup    => deprecated
createProcessGroupFor => new
joinProcessGroup      => same
setProcessGroupID     => deprecated
setProcessGroupIDOf   => new
parent bb8a27d1
No related branches found
No related tags found
No related merge requests found
...@@ -29,12 +29,13 @@ module System.Posix.Process ( ...@@ -29,12 +29,13 @@ module System.Posix.Process (
-- ** Process environment -- ** Process environment
getProcessID, getProcessID,
getParentProcessID, getParentProcessID,
getProcessGroupID,
-- ** Process groups -- ** Process groups
createProcessGroup, getProcessGroupID,
getProcessGroupIDOf,
createProcessGroupFor,
joinProcessGroup, joinProcessGroup,
setProcessGroupID, setProcessGroupIDOf,
-- ** Sessions -- ** Sessions
createSession, createSession,
...@@ -58,6 +59,10 @@ module System.Posix.Process ( ...@@ -58,6 +59,10 @@ module System.Posix.Process (
getAnyProcessStatus, getAnyProcessStatus,
getGroupProcessStatus, getGroupProcessStatus,
-- ** Deprecated
createProcessGroup,
setProcessGroupID,
) where ) where
#include "HsUnix.h" #include "HsUnix.h"
...@@ -118,11 +123,20 @@ getProcessGroupID = c_getpgrp ...@@ -118,11 +123,20 @@ getProcessGroupID = c_getpgrp
foreign import ccall unsafe "getpgrp" foreign import ccall unsafe "getpgrp"
c_getpgrp :: IO CPid c_getpgrp :: IO CPid
-- | @'createProcessGroup' pid@ calls @setpgid@ to make -- | @'getProcessGroupIDOf' pid@ calls @getpgid@ to obtain the
-- 'ProcessGroupID' for process @pid@.
getProcessGroupIDOf :: ProcessID -> IO ProcessGroupID
getProcessGroupIDOf pid =
throwErrnoIfMinus1 "getProcessGroupIDOf" (c_getpgid pid)
foreign import ccall unsafe "getpgid"
c_getpgid :: CPid -> IO CPid
-- | @'createProcessGroupFor' pid@ calls @setpgid@ to make
-- process @pid@ a new process group leader. -- process @pid@ a new process group leader.
createProcessGroup :: ProcessID -> IO ProcessGroupID createProcessGroupFor :: ProcessID -> IO ProcessGroupID
createProcessGroup pid = do createProcessGroupFor pid = do
throwErrnoIfMinus1_ "createProcessGroup" (c_setpgid pid 0) throwErrnoIfMinus1_ "createProcessGroupFor" (c_setpgid pid 0)
return pid return pid
-- | @'joinProcessGroup' pgid@ calls @setpgid@ to set the -- | @'joinProcessGroup' pgid@ calls @setpgid@ to set the
...@@ -131,11 +145,11 @@ joinProcessGroup :: ProcessGroupID -> IO () ...@@ -131,11 +145,11 @@ joinProcessGroup :: ProcessGroupID -> IO ()
joinProcessGroup pgid = joinProcessGroup pgid =
throwErrnoIfMinus1_ "joinProcessGroup" (c_setpgid 0 pgid) throwErrnoIfMinus1_ "joinProcessGroup" (c_setpgid 0 pgid)
-- | @'setProcessGroupID' pid pgid@ calls @setpgid@ to set the -- | @'setProcessGroupIDOf' pid pgid@ calls @setpgid@ to set the
-- 'ProcessGroupID' for process @pid@ to @pgid@. -- 'ProcessGroupIDOf' for process @pid@ to @pgid@.
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO () setProcessGroupIDOf :: ProcessID -> ProcessGroupID -> IO ()
setProcessGroupID pid pgid = setProcessGroupIDOf pid pgid =
throwErrnoIfMinus1_ "setProcessGroupID" (c_setpgid pid pgid) throwErrnoIfMinus1_ "setProcessGroupIDOf" (c_setpgid pid pgid)
foreign import ccall unsafe "setpgid" foreign import ccall unsafe "setpgid"
c_setpgid :: CPid -> CPid -> IO CInt c_setpgid :: CPid -> CPid -> IO CInt
...@@ -396,3 +410,27 @@ foreign import ccall unsafe "exit" ...@@ -396,3 +410,27 @@ foreign import ccall unsafe "exit"
c_exit :: CInt -> IO () c_exit :: CInt -> IO ()
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Deprecated or subject to change
{-# DEPRECATED createProcessGroup "This function is subject to change in future versions." #-}
-- | @'createProcessGroup' pid@ calls @setpgid@ to make
-- process @pid@ a new process group leader.
-- This function is currently deprecated,
-- and might be changed to making the current
-- process a new process group leader in future versions.
createProcessGroup :: ProcessID -> IO ProcessGroupID
createProcessGroup pid = do
throwErrnoIfMinus1_ "createProcessGroup" (c_setpgid pid 0)
return pid
{-# DEPRECATED setProcessGroupID "This function is subject to change in future versions." #-}
-- | @'setProcessGroupID' pid pgid@ calls @setpgid@ to set the
-- 'ProcessGroupID' for process @pid@ to @pgid@.
-- This function is currently deprecated,
-- and might be changed to setting the 'ProcessGroupID'
-- for the current process in future versions.
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO ()
setProcessGroupID pid pgid =
throwErrnoIfMinus1_ "setProcessGroupID" (c_setpgid pid pgid)
-- -----------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment