File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Killing a Process ..Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Killing a Process ..Please Help" Watch "Killing a Process ..Please Help" New topic
Author

Killing a Process ..Please Help

SBELUR BELUR
Greenhorn

Joined: Mar 01, 2005
Posts: 3
Hi

This is the situation.
From my Python script I start a Java Process which starts rmiregistry at some port

Now I am interested in Killing the rmiregistry process .
So i start another Python script which runs another Java Program ....
BUT now i am not sure how to kill the process ?

THIS IS MY QUESTION

Basically 2 jvms are run . IN one jvm i have process handle.
BUT how do i kill process from different JVM

If this is not possible i would lilke to know how to the below

in java

1> HOW DO I KILL A PROCESS RUNNING AT SOME PORT (In general)
(Can be started frrom different JVM ?)
2> Also is it possible to get PID of process from Java
Amit Bathla
Ranch Hand

Joined: Feb 11, 2005
Posts: 51
u can kill a process using (kill pid) command in linux or unix
but for this u have to know the pid of ur process this will be different every time u call ur prog.
in windows who knows ???


Amit
University of Florida
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

If you're using RMI already, why not just make a remote method called "shutdown()" or something to de-register from the rmiregistry and call System.exit()?

This is actually a lot easier to do than kill the process. To kill a process you have to code special ways on every platform you want to run on. Another problem is finding the exact process to kill - most JVMs name *every* java process running "java" - you have to run something internal to the program you want to kill to get the process id. This requires interacting with native code (again for each platform you want it to run on).

Another nice point to using a remote method to do this is that you can do a 'nice' shutdown and wait for all remote connections to close before actually shutting down. If you kill the process, it just shuts down right then, no matter what else is going on.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

Originally posted by amit bathla:
u can kill a process using (kill pid) command in linux or unix
but for this u have to know the pid of ur process this will be different every time u call ur prog.
in windows who knows ???


The Windows equivalent is "taskkill /pid processID".

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: Killing a Process ..Please Help