POSIX process group API reform proposal
Currently there is no way to find out the process group ID from a process ID. Also, process group IDs and process IDs share the same type, which prohibits static type-checking. (Note: The new API has been implemented in the new version of the unix library.)
Proposal[edit]
New type[edit]
It is proposed that System.Posix.Types have a new type ProcessGroupID where
newtype ProcessGroupID = ProcessGroupID CPid
New API[edit]
It is proposed that System.Posix.Process have these functions, (at least getProcessGroupIDOf)
-- wrappers for getpgrp() and getpgid(pid)
getProcessGroupID :: IO ProcessGroupID
getProcessGroupIDOf :: ProcessID -> IO ProcessGroupID
-- wrappers for setpgid(0,pgid) and setpgid(pid,pgid)
setProcessGroupID :: ProcessGroupID -> IO ()
setProcessGroupIDOf :: ProcessID -> ProcessGroupID -> IO ()
-- wrapper for setpgid(0,0) and setpgid(pid,0)
createProcessGroup :: IO ProcessGroupID
createProcessGroupFor :: ProcessID -> IO ProcessGroupID
-- a synonym of setProcessGroup
joinProcessGroup :: ProcessGroupID -> IO ()
Motivation[edit]
In POSIX, process groups and processes are two totally different concepts. It is unfortunate that the underlying type used in POSIX API is the same. Using different types for different concepts can help programmers avoid errors. For example, currently setProcessGroupID pgid pid
will not raise a compile-time error, and it will under the proposed implementation.
Also, these is no way to query the process group of a process now. This is needed for a careful implementation to the proposed functionality mentioned in GHC Ticket #3994. The getpgid has been standardized in POSIX.1-2001, which provides the functionality.
Backward compatibility[edit]
Unless people use CPid
explicitly to store process group IDs, all current codes using ProcessGroupID
should be complied without modification.
Two functions setProcessGroupID
and createProcessGroup
are backward incompatible with previous implantations. This proposal suggests announcing the proposed change and then really changes the interface in future versions.
Naming convention[edit]
The new API is trying to be more clear and consistent, while avoiding compatibility issues. The suffices Of or For are to indicate that the first argument is the process id of another process.