DrWarezz
asked on
End a Process.
Hi everyone,
is it possible to end a process in Java? I know how to start one, however, ending one doesn't seem the most easiest task.
Is there a simple method to do this? Or will it involve JNI? :o\
Thanks!
[r.D]
is it possible to end a process in Java? I know how to start one, however, ending one doesn't seem the most easiest task.
Is there a simple method to do this? Or will it involve JNI? :o\
Thanks!
[r.D]
Not possible as far as I know without JNI
ASKER
Hmm.. I was dreading that answer. lol :o\
Okay; do you JugglerW (or anyone else) no how to do this using JNI then??).
Thanks,
[r.D]
Okay; do you JugglerW (or anyone else) no how to do this using JNI then??).
Thanks,
[r.D]
Check out the exec methods in java.lang.Runtime
Process proc = Runtime.getRuntime().exec( ...)
proc.destroy(); //rudely ends process (maps to TerminateProcess on win32)
If you want fine grain control, you will probably want JNI, but this might work for you too.
Regards,
- Tim
Process proc = Runtime.getRuntime().exec(
proc.destroy(); //rudely ends process (maps to TerminateProcess on win32)
If you want fine grain control, you will probably want JNI, but this might work for you too.
Regards,
- Tim
Sorry, I didn't correctly read the question, but some of what I mentioned is still
applicable.
The crippling disadvantage of this is that you had to be the one to start the process
so you have a Process object.
When you get into JNI land, check out TerminateProcess (for win32),
If you are on Unix you can send a signal via:
kill(pid, SIGTERM);
or
kill(pid, SIGKILL);
applicable.
The crippling disadvantage of this is that you had to be the one to start the process
so you have a Process object.
When you get into JNI land, check out TerminateProcess (for win32),
If you are on Unix you can send a signal via:
kill(pid, SIGTERM);
or
kill(pid, SIGKILL);
ASKER
Okay; thanks, Tim.
Ermm.. Although I'm quite comfortable with Java as a whole, I haven't tackled JNI yet. Could you recommend a good JNI tutorial??
Thanks,
[r.D]
Ermm.. Although I'm quite comfortable with Java as a whole, I haven't tackled JNI yet. Could you recommend a good JNI tutorial??
Thanks,
[r.D]
Well how do you usually kill a process in your os? The best way would be to use JNI but as timbauer pointed out you could kill a process using the runtime class. On Linux for example you could do
Process proc = Runtime.getRuntime().exec( "kill 1857"); // kill the process with id 1857
Process proc = Runtime.getRuntime().exec(
Of course if you started a process by using a Process class it is far easier :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can't terminate or end process in a nice away in Java. You need to
either write something in JNI that calls either SendMessage() to end the
process nicely (will most likely require user interaction)
or
calls TerminateProcess() to KILL the process;
either install a program that does that and takes the process's name on the command line and call it via Runtime.exec().
To start a new process, call Runtime.exec().
either write something in JNI that calls either SendMessage() to end the
process nicely (will most likely require user interaction)
or
calls TerminateProcess() to KILL the process;
either install a program that does that and takes the process's name on the command line and call it via Runtime.exec().
To start a new process, call Runtime.exec().
ASKER
Okay, thanks everyone.
I'm going on holiday tomorrow, therefore I'm going to end this question now.
I think that girionis' answer would serve most useful to myself, but also, thanks for the JNI tutorial link, objects, and also, thanks to everyone else that took part.
Thanks,
[r.D]
I'm going on holiday tomorrow, therefore I'm going to end this question now.
I think that girionis' answer would serve most useful to myself, but also, thanks for the JNI tutorial link, objects, and also, thanks to everyone else that took part.
Thanks,
[r.D]
Thank you for accepting :)