I have a simple Haskell program that drops several processes, each of which sleeps for a certain number of seconds, and then an echo. No matter how many processes I fork, the second one does not seem to display any visible content on the terminal.
import System.Process (createProcess, proc, shell, CreateProcess) import Text.Printf (printf, PrintfArg) import Control.Concurrent (forkIO) import Control.Monad (void) sleep :: Integer -> CreateProcess sleep x = shell (printf "sleep %d; echo %d" xx) -- sleep x = shell (printf "sleep %d, echo %d, touch %d.haskell" xxx) main = foldr1 (>>) $ [ forkIO $ void $ createProcess task | task <- [ sleep 1, sleep 2, sleep 3, sleep 4, sleep 5] ]
produces
./scheduler user@name-of-computer $ 1 3 4 5
And if you run it with a commented line, and not just with print, you will see
$ 1.haskell 4.haskell 3.haskell 5.haskell
This behavior is also characteristic of Haskell. Perl does not show it.
use strict; use warnings FATAL => 'all'; sub sleep_echo { my ($second_count) = @_; my $cpid = fork; if ($cpid == 0) { exec "sleep $second_count; echo $second_count"; } } for (my $i = 1; $i <= 5; $i++) { sleep_echo($i); }
prints
user@name-of-computer $ 1 2 3 4 5
Any ideas on what's going on?
source share