Program won't go away!

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Wed Oct 18 13:51:49 EDT 2000


Wed, 18 Oct 2000 16:32:21 +0200, George Russell <ger at Informatik.Uni-Bremen.DE> pisze:

> > In a standalone GHC program, only the main thread is required to
> >   terminate in order for the process to terminate. 
> 
> I have a program (which does some fairly complex things with forking processes,

The above fact applies to threads (module Concurrent), not processes
(module Posix).

In some sense it does apply to processes, but the interface of
forkProcess allows to "continue execution" with the child process,
while the main process (parent) waits somewhere.

> the very last line of the "main" action is:
>       putStrLn "Test completed"
> The program prints "Test completed", but then hangs.

Quite possible. For example (untested):

main = do
    pid <- forkProcess
    case pid of
        Nothing -> return () -- This is the new process.
        Just _  -> do
            -- This is the old process.
            sleep 100; exitWith ExitSuccess
    -- This is the new process.
    putStrLn "Test completed"

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTÊPCZA
QRCZAK





More information about the Glasgow-haskell-bugs mailing list