Calling an external command from a Haskell program

John Meacham john at repetae.net
Tue Oct 21 15:38:13 EDT 2003


On Tue, Oct 21, 2003 at 02:09:50PM +0100, Simon Marlow wrote:
> 
>   http://www.haskell.org/pipermail/libraries/2003-May/000958.html
> 
> but didn't get any further.  The sticking point is that GHC needs a
> thread-safe wait() implementation, which means some hacking in the
> scheduler (there isn't even a good way to do this portably, because
> select() doesn't let you wait for process termination).

recently, I had need for a non-blocking System.system which interacted
well with concurrency and came up with the following 2 solutions:

1. trap SIGCHLD, once you get a a SIGCHLD you know wait() won't block.
unfortunatly there isn't a way to get at the siginfo_t with the standard
haskell libraries, but this can be worked around.

2. use pipe(2) or socketpair(2), fork (real fork, not forkIO), forked
process runs the program and write(2)s the processstatus to its end of
the pipe. the parent process does a Control.Concurrent.threadWaitRead on
it's end of the pipe, reads the exit status and returns it like normal.

I never got around to implementing either but I can't think of any
reason why they wouldn't work. 

perhaps we need a concurrency status page for library calls which we
know are concurrentsafe and ones we need to fix. (like System.system)
        John

-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john at foo.net
---------------------------------------------------------------------------


More information about the Libraries mailing list