Hi all,
I want to know how to close the application through process id(like kill command in unix)through java code.Is it possible in java?Please do me a favor.Thanks in advance.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi all,
I want to know how to close the application through process id(like kill command in unix)through java code.Is it possible in java?Please do me a favor.Thanks in advance.
There is the System.exit() method that will force your program to stop execution, but you need to be careful using this, especially if you have either an Event driven model or a multi-threaded program.
System.exit(0); // 0 is the return value, any int is acceptable
Subhvi, what you are proposing is not possible through Java alone. Java runs in the JVM which means it doesnt have access to anything going on outside of the JVM. If you want to do this you would have to look into an approach like using JNI to code a C solution using the windows functions which you can then call from within Java.
Regards,
Chris
PLEASE WHAT IS THIS ABOUT?
You may want to try using the Runtime.exec() function. You can try to retrieve a process ID for a running app, then run another exec command to try and shutdown the process. How you do so however is very platform dependent, and it may not behave universally
Last edited by copeg; January 14th, 2010 at 09:55 AM.
Ooh.. I totally misread what you wanted I thought you wanted to kill your java program's process, but instead you want to kill a different process... yes, see the above two posts for how to do that.