file descriptors
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Thu Oct 30 20:48:48 EDT 2008
On 2008 Oct 30, at 10:08, Johannes Waldmann wrote:
> are there any known issues
> with file handles/descriptors in ghc-compiled executables?
>
> My program has a lot of calls to System.Process.runInteractiveProcess
> and I'm running into unpredictable behaviour (sometimes the program
> just silently dies, sometimes it gets stuck)
runInteractiveProcess returns 3 filehandles and a process handle.
Either can cause problems: if you use too many filehandles, the
select()-based mechanism in the Haskell runtime will fail (select()
has a fairly low limit on filehandles as compared to poll(), epoll(),
and other mechanisms); if you spawn too many subprocesses without
reaping them (waitForProcess / getProcessExitCode) you will hit the
child process limit and not be able to create new child processes.
A third problem is that you can deadlock if you write too much data
without reading any back. Your best bet is to forkIO so input and
output are independent.
> Or perhaps you see anything that's wrong with my code here
> http://dfa.imn.htwk-leipzig.de/cgi-bin/cvsweb/box/src/SMT/Time.hs?rev=1.9
And there's a fourth problem: you hGetContents after blocking
waitForProcess. If the output is larger than the size of a pipe
buffer (often 512 bytes), the subprocess will block waiting for the
pipe to be read, while you're waiting for it to exit before reading
from the pipe.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
More information about the Glasgow-haskell-users
mailing list