[plt-scheme] the make-pipe

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Dec 6 09:21:25 EST 2007

At Thu, 6 Dec 2007 06:39:07 -0700, Matthew Flatt wrote:
> At Thu, 6 Dec 2007 18:20:07 +0800, yug at ios.ac.cn wrote:
> > [...]
> > 
> >   (define (x) (let-values ([(r w) (make-pipe)])
> >                 (process/ports w null-iport null-port "/sbin/sysctl -a")
> >                 (process/ports std-oport r  null-port "grep
> > vm.min_free_kbytes")
> >               ))
> >   (define (y) (process/ports std-oport null-iport null-port "/sbin/sysctl
> > -a| grep vm.min_free.kbytes"))
> >  [...]
> > 
> > Welcome to DrScheme, version 371.3-svn7nov2007 [3m].
> > Language: (module ...).
> > > (x)
> > (#f #f 11744 #f #<procedure:control>)
> > > (y)
> > (#f #f 11745 #f #<procedure:control>)
> > vm.min_free_kbytes = 5858
> > 
> > 1.why (x) and (y) is different?
> 
> I'm not sure. On my machine, they work the same when I run in plain
> MzScheme, but differently in DrScheme. I'll have to investigate more.

Ok, this isn't a bug...

When I run in MzScheme, then stdout is a terminal. Since `grep' sees
the terminal, then it writes output in line-buffered mode.

When running in DrScheme, though, `grep' doesn't see a terminal, and so
it uses block buffering for output. Then, since the pipe `w' is never
closed, there's no signal to `grep' that it needs to flush its output
buffer (which would finally deliver output to DrScheme). the `grep'
process just waits around in the background.

Using the alternate implementation of `x' that I provided avoids the
problem.

Matthew



Posted on the users mailing list.