ctrl - c not working in pipe

Discussion in 'Java' started by peter, Aug 17, 2009.

  1. peter

    peter Guest

    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 ()
    peter, Aug 17, 2009
    #1
    1. Advertising

  2. peter

    Lew Guest

    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, Aug 17, 2009
    #2
    1. Advertising

  3. peter

    Lew Guest

    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
    Lew, Aug 17, 2009
    #3
  4. In article <h6akto$bnf$>, Lew <>
    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>
    John B. Matthews, Aug 17, 2009
    #4
  5. peter

    Roedy Green Guest

    On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <>
    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.
    Roedy Green, Aug 17, 2009
    #5
  6. peter

    peter Guest

    On 8月18æ—¥, 上åˆ3時06分, Roedy Green <>
    wrote:
    > On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <>
    > 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
    peter, Aug 18, 2009
    #6
  7. peter

    Lew Guest

    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
    Lew, Aug 18, 2009
    #7
  8. peter wrote:
    > On 8?18?, ??3?06?, Roedy Green <>
    > wrote:
    >> On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <>
    >> 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.
    Mike Schilling, Aug 18, 2009
    #8
  9. peter

    peter Guest

    On 8月19æ—¥, 上åˆ1時10分, "Mike Schilling" <>
    wrote:
    > peter wrote:
    > > On 8?18?, ??3?06?, Roedy Green <>
    > > wrote:
    > >> On Sun, 16 Aug 2009 20:44:26 -0700 (PDT), peter <>
    > >> 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
    peter, Aug 19, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C++
    Replies:
    5
    Views:
    636
    CBFalconer
    Aug 15, 2003
  2. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C Programming
    Replies:
    5
    Views:
    648
    CBFalconer
    Aug 15, 2003
  3. Angus
    Replies:
    5
    Views:
    2,085
    Michael Rauscher
    Nov 18, 2006
  4. Replies:
    2
    Views:
    1,394
    Munna
    Jul 10, 2008
  5. Replies:
    0
    Views:
    547
Loading...

Share This Page