Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   ctrl - c not working in pipe (http://www.velocityreviews.com/forums/t695054-ctrl-c-not-working-in-pipe.html)

peter 08-17-2009 03:44 AM

ctrl - c not working in pipe
 
Dear All


ProcessBuilder pb = new ProcessBuilder(bochsPath, "-q", "-f",
"bochsrc.bxrc");
pb.directory(new File("test"));
pb.redirectErrorStream(true);

p = pb.start();
p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
ctrl -c signal, but not working

thanks
from Peter (cmk128@hotmail.com)

Lew 08-17-2009 04:01 AM

Re: ctrl - c not working in pipe
 
peter wrote:
> Dear All
>
>
> ProcessBuilder pb = new ProcessBuilder(bochsPath, "-q", "-f",
> "bochsrc.bxrc");
> pb.directory(new File("test"));
> pb.redirectErrorStream(true);
>
> p = pb.start();
> p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
> ctrl -c signal, but not working


0x3 is just a value - it doesn't trigger a signal unless the OS receives a
command to send a signal. The keyboard driver has a trap to convert "Ctrl-C"
into a signal, which the OS delivers instead of a byte with value 3. What you
did is bypass that mechanism and simply send the byte.

You can see this in Linux or Cygwin or any bash shell environment by entering
the command
$ echo $'\x3'this is a test

That merely sends the byte "0x03" to the output but does not raise the signal
that Ctrl-C would.

I'm sorry; I don't know how to send the signal.

--
Lew

Lew 08-17-2009 04:05 AM

Re: ctrl - c not working in pipe
 
Lew wrote:
> peter wrote:
>> Dear All
>>
>>
>> ProcessBuilder pb = new ProcessBuilder(bochsPath, "-q", "-f",
>> "bochsrc.bxrc");
>> pb.directory(new File("test"));
>> pb.redirectErrorStream(true);
>>
>> p = pb.start();
>> p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
>> ctrl -c signal, but not working

>
> 0x3 is just a value - it doesn't trigger a signal unless the OS receives
> a command to send a signal. The keyboard driver has a trap to convert
> "Ctrl-C" into a signal, which the OS delivers instead of a byte with
> value 3. What you did is bypass that mechanism and simply send the byte.
>
> You can see this in Linux or Cygwin or any bash shell environment by
> entering the command
> $ echo $'\x3'this is a test
>
> That merely sends the byte "0x03" to the output but does not raise the
> signal that Ctrl-C would.
>
> I'm sorry; I don't know how to send the signal.


Unless you figure out the process id (PID) of the started 'Process' and issue
a "kill -int <PID>" to it.

--
Lew

John B. Matthews 08-17-2009 03:42 PM

Re: ctrl - c not working in pipe
 
In article <h6akto$bnf$2@news.albasani.net>, Lew <noone@lewscanon.com>
wrote:

> Lew wrote:
> > peter wrote:
> >> Dear All
> >>
> >> ProcessBuilder pb = new ProcessBuilder(bochsPath, "-q", "-f",
> >> "bochsrc.bxrc");
> >> pb.directory(new File("test"));
> >> pb.redirectErrorStream(true);
> >>
> >> p = pb.start();
> >> p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
> >> ctrl -c signal, but not working

> >
> > 0x3 is just a value - it doesn't trigger a signal unless the OS
> > receives a command to send a signal. The keyboard driver has a
> > trap to convert "Ctrl-C" into a signal, which the OS delivers
> > instead of a byte with value 3. What you did is bypass that
> > mechanism and simply send the byte.
> >
> > You can see this in Linux or Cygwin or any bash shell environment
> > by entering the command
> > $ echo $'\x3'this is a test
> >
> > That merely sends the byte "0x03" to the output but does not raise
> > the signal that Ctrl-C would.
> >
> > I'm sorry; I don't know how to send the signal.

>
> Unless you figure out the process id (PID) of the started 'Process'
> and issue a "kill -int <PID>" to it.


The kill command is a good, general-purpose way to send any signal:

<http://linux.die.net/man/2/kill>

Getting the PID can be cumbersome, and writing the PID to a file may be
convenient. Many system services store the value in /var/log/*.pid. In
this case, I wonder if the OP might simply use p.destroy() instead.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Roedy Green 08-17-2009 07:06 PM

Re: ctrl - c not working in pipe
 
On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <cmk128@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
>ctrl -c signal, but not working


Other than the problems others have mentioned, a byte can get stuck
because you did not flush, or because the input is blocking. You
really need multiple threads to control a child.

see http://mindprod.com/jgloss/exec.html

--
Roedy Green Canadian Mind Products
http://mindprod.com

http://thecovemovie.com : The Cove: a documentary about Japan's secret atrocities against dolphins.

peter 08-18-2009 03:12 AM

Re: ctrl - c not working in pipe
 
On 8月18日, 上午3時06分, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <cmk...@gmail.com>
> wrote, quoted or indirectly quoted someone who said :
>
> >p.getOutputStream.write((byte)0x3); <---- *I want to send a SININT,
> >ctrl -c signal, but not working

>
> Other than the problems others have mentioned, a byte can get stuck
> because you did not flush, or because the input is blocking. *You
> really need multiple threads to control a child.
>
> seehttp://mindprod.com/jgloss/exec.html
>
> --
> Roedy Green Canadian Mind Productshttp://mindprod.com
>
> http://thecovemovie.com: The Cove: a documentary about Japan's secret atrocities against dolphins.


searched around for several days. Java has no ability to send SIGINT
to other process. Even in visual c++, no way to do it too.
thanks
from Peter

Lew 08-18-2009 03:32 AM

Re: ctrl - c not working in pipe
 
peter wrote:
> searched around for several days. Java has no ability to send SIGINT
> to other process. Even in visual c++, no way to do it too.


No direct ability. Java can do it indirectly as described upthread.

--
Lew

Mike Schilling 08-18-2009 05:10 PM

Re: ctrl - c not working in pipe
 
peter wrote:
> On 8?18?, ??3?06?, Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
>> On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <cmk...@gmail.com>
>> wrote, quoted or indirectly quoted someone who said :
>>
>>> p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
>>> ctrl -c signal, but not working

>>
>> Other than the problems others have mentioned, a byte can get stuck
>> because you did not flush, or because the input is blocking. You
>> really need multiple threads to control a child.
>>
>> seehttp://mindprod.com/jgloss/exec.html


>
> searched around for several days. Java has no ability to send SIGINT
> to other process


Since SIGINT is OS-specific, that's what you'd expect.



peter 08-19-2009 02:06 AM

Re: ctrl - c not working in pipe
 
On 8月19日, 上午1時10分, "Mike Schilling" <mscottschill...@hotmail.com>
wrote:
> peter wrote:
> > On 8?18?, ??3?06?, Roedy Green <see_webs...@mindprod.com.invalid>
> > wrote:
> >> On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <cmk...@gmail.com>
> >> wrote, quoted or indirectly quoted someone who said :

>
> >>> p.getOutputStream.write((byte)0x3); <---- I want to send a SININT,
> >>> ctrl -c signal, but not working

>
> >> Other than the problems others have mentioned, a byte can get stuck
> >> because you did not flush, or because the input is blocking. You
> >> really need multiple threads to control a child.

>
> >> seehttp://mindprod.com/jgloss/exec.html

>
> > searched around for several days. Java has no ability to send SIGINT
> > to other process

>
> Since SIGINT is OS-specific, that's what you'd expect.


this is very trouble in windows. I can execute a "kill -2" command.
But in windows, cannot.
I need it to make my bochs gui debugger http://code.google.com/p/peter-bochs
to work in windows.
thanks
from Peter


All times are GMT. The time now is 10:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.