POSIX process group API reform proposal
From HaskellWiki
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.)
Contents |
1 Proposal
1.1 New type
It is proposed that System.Posix.Types have a new type ProcessGroupID where
newtype ProcessGroupID = ProcessGroupID CPid
1.2 New API
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 ()
2 Motivation
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, currentlyAlso, 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.
3 Backward compatibility
Unless people use4 Naming convention
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.
