aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Process.hsc
diff options
context:
space:
mode:
authorGravatar stolz <unknown>2003-02-28 12:34:45 +0000
committerGravatar stolz <unknown>2003-02-28 12:34:45 +0000
commitbf3d4ea65818fa36926eb0de67dab698bd9a2d17 (patch)
tree71cd3303ce3744ef9494527f8c012e8c9740582e /System/Posix/Process.hsc
parentf48e575611b5ba4be82b0f904a1642c0cad628b7 (diff)
[project @ 2003-02-28 12:34:45 by stolz]
- Rename System.Posix.Process.forkProcess to forkProcessAll - Move GHC.Conc.forkProcess to System.Posix with type 'Maybe ProcessID' Prompted by: George Russel
Diffstat (limited to 'System/Posix/Process.hsc')
-rw-r--r--System/Posix/Process.hsc29
1 files changed, 27 insertions, 2 deletions
diff --git a/System/Posix/Process.hsc b/System/Posix/Process.hsc
index ec0bc33..5549d23 100644
--- a/System/Posix/Process.hsc
+++ b/System/Posix/Process.hsc
@@ -17,7 +17,8 @@ module System.Posix.Process (
-- * Processes
-- ** Forking and executing
- forkProcess, executeFile,
+ forkProcess, forkProcessAll,
+ executeFile,
-- ** Exiting
exitImmediately,
@@ -62,6 +63,7 @@ module System.Posix.Process (
#include "HsUnix.h"
+import GHC.Conc ( forkProcessPrim )
import Foreign
import Foreign.C
import System.IO
@@ -199,8 +201,32 @@ foreign import ccall unsafe "setpriority"
-- -----------------------------------------------------------------------------
-- Forking, execution
+{- | 'forkProcess' is a wrapper around "GHC.Conc.forkProcessPrim" similar to
+'forkProcessAll' which returns a Maybe-type. The child receives @Nothing@,
+the parent @Just (pid::ProcessID)@. In case of an error, an exception is thrown.
+
+NOTE: currently, main threads are not stopped in the child process.
+To work around this problem, call 'forkProcess' from the main thread.
+
+If you really want to copy all threads into the new process, use
+'forkProcessAll' instead.
+-}
+
forkProcess :: IO (Maybe ProcessID)
forkProcess = do
+ pid <- throwErrnoIfMinus1 "forkProcess" forkProcessPrim
+ case pid of
+ 0 -> return Nothing
+ _ -> return (Just (fromIntegral pid))
+
+{- | 'forkProcessAll' is the low-level wrapper for the @fork@ system-call.
+Standard disclaimer for lazy I\/O, shared file handles etc. apply. Notice that
+all Concurrent Haskell threads will be copied into the new process. See
+'forkProcess' on how to start a new process with only one active thread.
+-}
+
+forkProcessAll :: IO (Maybe ProcessID)
+forkProcessAll = do
r <- throwErrnoIfMinus1 "forkProcess" c_fork
case r of
0 -> return Nothing
@@ -209,7 +235,6 @@ forkProcess = do
foreign import ccall unsafe "fork"
c_fork :: IO CInt
-
executeFile :: FilePath -- Command
-> Bool -- Search PATH?
-> [String] -- Arguments