HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Running processes concurrently

Categories: How to | Code

This example forks many processes in parallel, then waits for each process to exit. Finally, it prints the number of failures.

import System.Process
import Control.Concurrent
import System.Exit
 
main = do
        let cmds = replicate 100 "sleep 10s"
        ps <- mapM runCommand cmds
        es <- mapM waitForProcess ps
        case length . filter (/= ExitSuccess) $ es of
            0 -> putStrLn "All commands ran successfully."
            n -> putStrLn ("There were " ++ show n ++ " failures.")

Retrieved from "http://haskell.org/haskellwiki/Running_processes_concurrently"

This page has been accessed 746 times. This page was last modified 21:22, 23 June 2007. Recent content is available under a simple permissive license.