Difference between revisions of "POSIX process group API reform proposal"

From HaskellWiki
Jump to navigation Jump to search
(creation of this proposal)
 

Revision as of 03:45, 4 May 2011

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.

Proposal

New type

It is proposed that System.Posix.Types have a new type CPgid and ProcessGroupID where

type ProcessGroupID = CPgid

New API

It is proposed that System.Posix.Process have these functions, (at least getProcessGroupIDOf)

-- wrapper for getpgid(pid)
getProcessGroupIDOf :: ProcessID -> IO ProcessGroupID

-- wrapper for setpgid(pid,pgid)
setProcessGroupIDOf :: ProcessID -> ProcessGroupID -> IO ()

-- wrapper for setpgid(pid,0)
createProcessGroupFor :: ProcessID -> IO ProcessGroupID

-- wrapper for getpgid(0)
getCurrentProcessGroupID :: IO ProcessGroupID

-- wrapper for setpgid(0,pgid)
setCurrentProcessGroupID :: ProcessGroupID -> IO ()

-- wrapper for setpgid(0,pgid) (same as now)
joinProcessGroup :: ProcessGroupID -> IO ()

And these functions for backward compatibility

-- wrapper for getpgid(0)
getProcessGroupID :: IO ProcessGroupID

-- wrapper for setpgid(pid,0)
createProcessGroup :: ProcessID -> IO ProcessGroupID

-- wrapper for setpgid(pid,gpid) (should be deprecated)
setProcessGroupID :: ProcessID -> ProcessGroupID -> IO ()

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, 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 proves the functionality.

Backward compatibility

Unless people use CPid explicitly to store process group IDs, all current codes should be able to complied without modification.

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 a process id, not a process group id.