I need to write code to kill a process using C language.
I should write C code and use it in java using JNI
Is there an API in C that kills a process given its name or something like pid in unix?
<Karthik> Future SCJP
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32421
posted
0
You don't need to use JNI or C. You can use Runtime.exec or ProcessBuilder to launch whatever Unix utility you prefer to handle this (most likely ps and kill).
But i was asked to integrate this into java code and creat an APi, how do i do that.
2) I was given a specification saying that we cant kill a process on server cleanly using java, so write native code in C and intgrate into java using JNI.
But how to kill a process using C?
Is there a way to kill it cleanly in java?
will destroy() method kill a process cleanly?
HELP ME OUT PLEASE...
Im a fresher into the company, so facing an uphill task understanding things..
For Windows, if you want to use JNI -for which there is no need- then you need to find a C/C++ API that can terminate processes. Some rudimentary code for that is mentioned in http://www.coderanch.com/t/385840/Java-General-intermediate/java/Relaunch-program-if-it-crashes You can also use Windows' tasklist utility (for which the Runtime.exec/ProcessBuilder approach should also work).
Abhinav Trivedi
Greenhorn
Joined: Mar 29, 2009
Posts: 10
posted
0
karthik deepak wrote:I need to write code to kill a process using C language.
I should write C code and use it in java using JNI
Is there an API in C that kills a process given its name or something like pid in unix?
Actually you can do it with taskkill command that default shipps with windows. You can check the syntax. And in C language and if you are using borland editor import dos.h and use int86 interrupt handler to kill a process. There is also the unixtodos function. Hope you will get the idea.