[squeak-dev] Does PipeableOSProcess require some finalization/clean up?

David T. Lewis lewis at mail.msen.com
Wed May 16 19:33:39 UTC 2012


Hi Yoshiki,

Yes, a PipeableOSProcess does require cleanup to close open pipe
handles. I am away and cannot look at the code right now, but check
#closePipes, #close, etc. This is not a CogVM or Mac VM issue.

When running in a CommandShell, the cleanup happens automatically,
but not when you are interacting directly with an individual
PipeableOSProcess.

The resources in question are the unix file handles associated with
OS pipe endpoints. For example, the standard output from your
external command is connected to your image via an OS pipe, and
the reader end of that pipe is represented in your image as a
file stream. Just as with a file, you need to keep that file stream
open until you are done using it, and the underlying OS file
handle does not go away until the file stream is closed.

The reason that garbage collection does not free up the handles
is that "OSProcess thisOSProcess allMyChildren" has a dictionary
of all child processes that have been run, including the PipeableOSProcess
that you ran. I think that if you empty that dictionary, the
garbage collection will probably finalize the pipes for you.
But the better thing to do is close the pipes explicitly.

Dave


On Wed, May 16, 2012 at 09:45:55AM -0700, Yoshiki Ohshima wrote:
> In a fully updated trunk 4.4 alpha image (#12041), load
> OSProcess-dtl.70 and CommandShell-dtl.61.  And with the latest Cog VM
> ('Croquet Closure Cog VM [CoInterpreter VMMaker.oscog-eem.157] Croquet
> Cog 4.0.2550') on MacOS 10.7.4.  If I evaluate:
> 
> -------------------------------------
> v := [1 to: 256 do: [:i |
> 		(PipeableOSProcess command: 'echo hello') output.
> 		Transcript print: i; cr.
> 		(Delay forMilliseconds: 50) wait.]].
> v fork
> -------------------------------------
> 
> and when i reaches around 242, I get an error that says "cannot create
> OS pipe" (you actually don't get the reporting to Transcript but...).
> Garbage collection does not clear the issue (as the comment in
> #register: of AttachableFileStream suggests).  With lsof, I can see
> that it keeps all pipes.
> 
> Do I need to make some more calls to have them clean up?  (Or, is this
> another symptom of the file open/close issue with CogVM on Mac VM?)
> 
> -- Yoshiki


More information about the Squeak-dev mailing list