[squeak-dev] OSProcess question
David T. Lewis
lewis at mail.msen.com
Mon Mar 10 23:37:49 UTC 2008
On Mon, Mar 10, 2008 at 11:13:42AM -0700, Andreas Raab wrote:
> We have a situation where some code reliably locks up when used like here:
> p := OSProcess command: 'chmod +x ', path.
> [p isComplete] whileFalse.
> This hangs quite reliably in the second line and I'm *assuming* that we
> need to yield/delay execution while waiting. Is this correct? I was
> trying to trace through the code paths which update the runState but it
> wasn't immediately clear where this comes from.
Yes, you should add a delay in the loop, or use this (which adds the
delay for you):
p := OSProcess waitForCommand: 'chmod +x ', path
The run state of an external OS process is updated by a separate Squeak
process (evaluate "OSProcess accessor grimReaperProcess"), so you need
to wait for the grimReaperProcess to react to the external process
exit notification. On Unix, this is a SIGCHLD, which is caught by OSPP,
which sends #signalSemaphoreWithIndex:, which wakes up the grimReaperProcess,
which calls #primitiveReapChildProcess to clean up and obtain the child
exit status. After all of this has happened, #isComplete will answer
BTW, you can receive direct notification of a change in run state for
an external OS process (ExternalOSProcess>>update:), but this executes
in the context of the grimReaperProcess, so use this with care.
More information about the Squeak-dev