Canceling a PipeableOSProcess

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Canceling a PipeableOSProcess

Sean P. DeNigris
Administrator
How do I cancel a running PipeableOSProcess that is taking a long time, like ctrl-c at the command line?

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canceling a PipeableOSProcess

David T. Lewis
On Fri, Nov 04, 2011 at 01:53:25PM -0700, Sean P. DeNigris wrote:
> How do I cancel a running PipeableOSProcess that is taking a long time, like
> ctrl-c at the command line?

You can kill the external process with a unix signal like this:

  p := PipeableOSProcess command: '/bin/sh'.
  p processProxy terminate.

However, in general, it is better to permit the external process to exit
normally. Usually this just involves closing the input to the process
and reading any available output. For example, if you run /bin/sh in a
PipeableOSProcess, you can terminate it simply by closing the input to
the shell to allow the shell to exit normally, which may be done like
this:

  p := PipeableOSProcess command: '/bin/sh'.
  p close.

Try stepping through these examples in the Smalltalk debugger to get a
better understanding of what is actually being done. Note that it is
entirely possible to send the exact equivalent of ctrl-c (which is a
unix SIGINT signal sent to the process) if you need to do so. See
method UnixOSProcessAccessor>>primSendSigintTo: to see how it is done.
But I suspect that you do not really need to do this, and I am only
mentioning it in case you are interested in the gory details ;)

HTH,
Dave

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Canceling a PipeableOSProcess

Sean P. DeNigris
Administrator
David T. Lewis wrote
You can kill the external process with a unix signal like this:
  p processProxy terminate.
Cool, thanks.

David T. Lewis wrote
However, in general, it is better to permit the external process to exit
normally.
Better how? On the Unix side, or the Squeak side?

David T. Lewis wrote
Note that it is
entirely possible to send the exact equivalent of ctrl-c (which is a
unix SIGINT signal sent to the process)
I'll have to take a look. I was asking because I am calling Mac OS X's hdiutil, which can take ~5-10 minutes to run, and sometimes I want to cancel the op. I mentioned Ctrl-c specifically because I know it responds to it; on the CLI, it gives a message about canceling before stopping.

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canceling a PipeableOSProcess

David T. Lewis
On Fri, Nov 04, 2011 at 05:30:30PM -0700, Sean P. DeNigris wrote:

>
> David T. Lewis wrote:
> >
> > You can kill the external process with a unix signal like this:
> >   p processProxy terminate.
> >
> Cool, thanks.
>
>
> David T. Lewis wrote:
> >
> > However, in general, it is better to permit the external process to exit
> > normally.
> >
> Better how? On the Unix side, or the Squeak side?
>
>
> David T. Lewis wrote:
> >
> > Note that it is
> > entirely possible to send the exact equivalent of ctrl-c (which is a
> > unix SIGINT signal sent to the process)
> >
> I'll have to take a look. I was asking because I am calling Mac OS X's
> hdiutil, which can take ~5-10 minutes to run, and sometimes I want to cancel
> the op. I mentioned Ctrl-c specifically because I know it responds to it; on
> the CLI, it gives a message about canceling before stopping.

In that case, try doing something more like this:

  p := PipeableOSProcess command: '/bin/sh'.
  p processProxy sigint.

But use hdiutil rather than the /bin/sh that I use in the above example.
The #sigint message will send a unix SIGINT signal to the external
process, which should be exactly equivalent to doing ctrl-c if you
were running hdiutil from a terminal window on the Mac (but I do
not actually have a Mac, so I might be getting the details wrong).

Dave

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Canceling a PipeableOSProcess

Sean P. DeNigris
Administrator
David T. Lewis wrote
In that case, try doing something more like this:

  p := PipeableOSProcess command: '/bin/sh'.
  p processProxy sigint.
Great, thanks. That looks like exactly what I wanted.

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canceling a PipeableOSProcess

Sean P. DeNigris
Administrator
In reply to this post by David T. Lewis
David T. Lewis wrote
  p processProxy sigint.
It seems to have worked like a charm. Thanks again.
Cheers,
Sean