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

From HaskellWiki
Jump to navigation Jump to search
(→‎New API: Revise the proposed API to make them clear.)
(→‎Backward compatibility: The revised API breaks the compatibility of two functions.)
Line 37: Line 37:
 
== Backward compatibility ==
 
== Backward compatibility ==
   
Unless people use <hask>CPid</hask> explicitly to store process group IDs, all current codes should be able to complied without modification.
+
Unless people use <hask>CPid</hask> explicitly to store process group IDs, all current codes using <hask>ProcessGroupID</hask> should be complied without modification.
  +
  +
Two functions <hask>setProcessGroupID</hask> and <hask>createProcessGroup</hask> are backward incompatible with previous implantations. This proposal suggests announcing the proposed change and then really changes the interface in future versions.
   
 
== Naming convention ==
 
== Naming convention ==

Revision as of 09:58, 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 ProcessGroupID where

newtype ProcessGroupID = ProcessGroupID CPid

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(pid,0) and setpgid(0,0)
createProcessGroup :: IO ProcessGroupID
createProcessGroupFor :: ProcessID -> IO ProcessGroupID

-- a synonym of setProcessGroup
joinProcessGroup :: 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 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

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.