Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > gracefully terminate a JVM on windows if can't ctrl-c shell

Reply
Thread Tools

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

 
 
Michael Grove
Guest
Posts: n/a
 
      06-12-2005
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


 
Reply With Quote
 
 
 
 
millerch
Guest
Posts: n/a
 
      06-13-2005
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
>
>

 
Reply With Quote
 
 
 
 
millerch
Guest
Posts: n/a
 
      06-13-2005
Sorry, that won't work under windows...
have you looked at
http://www.latenighthacking.com/proj...03/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/de...ectrlevent.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
>>
>>

 
Reply With Quote
 
Michael Grove
Guest
Posts: n/a
 
      06-14-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sorry, that won't work under windows...
> have you looked at
> http://www.latenighthacking.com/proj...03/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/de...ectrlevent.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
>>>
>>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Terminate a python script from linux shell / bash script Gros Bedo Python 0 07-13-2008 06:59 PM
Re: Terminate a python script from linux shell / bash script norseman Python 0 07-10-2008 09:44 PM
RE: Terminate a python script from linux shell / bash script Gros Bedo Python 1 07-10-2008 08:50 PM
Terminate a python script from linux shell / bash script Gros Bedo Python 2 07-10-2008 08:42 AM
How to quit a Windows GUI program gracefully with Python under Cygwin? KB Python 4 08-13-2005 12:42 AM



Advertisments