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.
Printable View
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.
Code :
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
Ooh.. I totally misread what you wanted :P 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.