On Wed, Apr 18, 2012 at 02:47:38PM -0700, Sean P. DeNigris wrote:
Sometimes, OSProcess hangs even though the underlying command has completed.
For example, on Mac 10.7.3: p := PipeableOSProcess waitForCommand: 'ps -ax -o pid,command' "never returns" even though "p upToEnd" immediately returns the output if I use #command: instead of waiting.
How best to handle this?
Thanks. Sean
PipeableOSProcess class>>waitForCommand: is just a loop that waits for the command (running in an external process) to complete. If the command does not complete, it keeps looping. The program that you are running (/bin/ps) will try to exit after it has written all of its output to its standard output, which in this case is a pipe connected back to your VM. But if the pipe fills up (the operating system will put some limit on this), the /bin/ps program will block trying to write to its output until somebody reads some of that data from the pipe. If nobody reads the output, the /bin/ps program will just block forever, and it will seem to be "stuck" and will never exit. What to do? Read the data from the output of the PipeableOSProcess. The /bin/ps program will then be unblocked, and it will finish writing its output and then exit normally. Dave