gracefully terminate a JVM on windows if can't ctrl-c shell

Discussion in 'Java' started by Michael Grove, Jun 13, 2005.

  1. hi,

    if i start a JVM on windows from one shell (or process), is there a way to
    send the equivalent of a ctrl-c to the JVM from another shell or process?
    on unix a regular kill gracefully terminates the JVM (shutdown hooks
    invoked). on windows, unless i have access to the shell that started the
    JVM, i'm not sure how to gracefully stop the JVM. i believe if i started
    the JVM through JNI i could use JNI to stop the JVM gracefully (think that's
    how JavaService does it) but i need to be able to stop a JVM started by
    another process that invokes java.exe directly. i'm hoping i can write a
    program that, given the JVM PID, sends a ctrl-c equivalent to the JVM.

    ideas? didn't see this covered in a google search, sorry if i missed it.

    thanks.

    -mike
     
    Michael Grove, Jun 13, 2005
    #1
    1. Advertising

  2. Michael Grove

    millerch Guest

    How about "kill -2 PID" ?

    Michael Grove wrote:
    > hi,
    >
    > if i start a JVM on windows from one shell (or process), is there a way to
    > send the equivalent of a ctrl-c to the JVM from another shell or process?
    > on unix a regular kill gracefully terminates the JVM (shutdown hooks
    > invoked). on windows, unless i have access to the shell that started the
    > JVM, i'm not sure how to gracefully stop the JVM. i believe if i started
    > the JVM through JNI i could use JNI to stop the JVM gracefully (think that's
    > how JavaService does it) but i need to be able to stop a JVM started by
    > another process that invokes java.exe directly. i'm hoping i can write a
    > program that, given the JVM PID, sends a ctrl-c equivalent to the JVM.
    >
    > ideas? didn't see this covered in a google search, sorry if i missed it.
    >
    > thanks.
    >
    > -mike
    >
    >
     
    millerch, Jun 13, 2005
    #2
    1. Advertising

  3. Michael Grove

    millerch Guest

    Sorry, that won't work under windows...
    have you looked at
    http://www.latenighthacking.com/projects/2003/sendSignal/ ?

    You can call GenerateConsoleCtrlEvent, or write something to wrap around
    it. But that will only send a ctrl-c to a process in the same group,
    which presumably is ok as it started from the same console...

    (http://msdn.microsoft.com/library/d...-us/dllproc/base/generateconsolectrlevent.asp)

    Hope that helps!

    millerch wrote:
    > How about "kill -2 PID" ?
    >
    > Michael Grove wrote:
    >
    >>hi,
    >>
    >>if i start a JVM on windows from one shell (or process), is there a way to
    >>send the equivalent of a ctrl-c to the JVM from another shell or process?
    >>on unix a regular kill gracefully terminates the JVM (shutdown hooks
    >>invoked). on windows, unless i have access to the shell that started the
    >>JVM, i'm not sure how to gracefully stop the JVM. i believe if i started
    >>the JVM through JNI i could use JNI to stop the JVM gracefully (think that's
    >>how JavaService does it) but i need to be able to stop a JVM started by
    >>another process that invokes java.exe directly. i'm hoping i can write a
    >>program that, given the JVM PID, sends a ctrl-c equivalent to the JVM.
    >>
    >>ideas? didn't see this covered in a google search, sorry if i missed it.
    >>
    >>thanks.
    >>
    >>-mike
    >>
    >>
     
    millerch, Jun 13, 2005
    #3
  4. thanks for the link. i was able to modify the source to SendSignal,
    replacing every CTRL_BREAK_EVENT with CTRL_C_EVENT, and the program does
    what i want. fairly complex - you have to inject a thread into the JVM
    process, then send it the CTRL_C_EVENT - but it's the only solution i'm
    aware of right now.

    thanks again.

    -mike

    "millerch" <> wrote in message
    news:...
    > Sorry, that won't work under windows...
    > have you looked at
    > http://www.latenighthacking.com/projects/2003/sendSignal/ ?
    >
    > You can call GenerateConsoleCtrlEvent, or write something to wrap around
    > it. But that will only send a ctrl-c to a process in the same group,
    > which presumably is ok as it started from the same console...
    >
    > (http://msdn.microsoft.com/library/d...-us/dllproc/base/generateconsolectrlevent.asp)
    >
    > Hope that helps!
    >
    > millerch wrote:
    >> How about "kill -2 PID" ?
    >>
    >> Michael Grove wrote:
    >>
    >>>hi,
    >>>
    >>>if i start a JVM on windows from one shell (or process), is there a way
    >>>to
    >>>send the equivalent of a ctrl-c to the JVM from another shell or process?
    >>>on unix a regular kill gracefully terminates the JVM (shutdown hooks
    >>>invoked). on windows, unless i have access to the shell that started the
    >>>JVM, i'm not sure how to gracefully stop the JVM. i believe if i started
    >>>the JVM through JNI i could use JNI to stop the JVM gracefully (think
    >>>that's
    >>>how JavaService does it) but i need to be able to stop a JVM started by
    >>>another process that invokes java.exe directly. i'm hoping i can write a
    >>>program that, given the JVM PID, sends a ctrl-c equivalent to the JVM.
    >>>
    >>>ideas? didn't see this covered in a google search, sorry if i missed it.
    >>>
    >>>thanks.
    >>>
    >>>-mike
    >>>
    >>>
     
    Michael Grove, Jun 14, 2005
    #4
    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. Jabba Laci
    Replies:
    0
    Views:
    93
    Jabba Laci
    Mar 22, 2014
  2. Dave Angel
    Replies:
    0
    Views:
    61
    Dave Angel
    Mar 22, 2014
  3. Jabba Laci
    Replies:
    0
    Views:
    49
    Jabba Laci
    Mar 22, 2014
  4. Chris Angelico
    Replies:
    0
    Views:
    51
    Chris Angelico
    Mar 22, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    61
    Terry Reedy
    Mar 22, 2014
Loading...

Share This Page