How to stop a process from a java application

Y

Yadagiri Rao KP

Sir,
I am doing this assignment.For example if I run "ls" command in a java
application and the file contents are big and I want to stop the
process.
I know that "kill" will be a better option but this takes a pid.Am I
right? How should I know when I am running a java application the pid
of the unix command ?
Or is there any other way to stop such as --on unix machine we do "q!"
to stop a process.
Pls guide.
 
M

Moshe Sayag

Hi,

If You start the process from another java process you get a reference
to a Process, which you can "kill"

Try something like:

Process p = Runtime.exec("ls");
.....
if (...) {
p.destroy();
}

Hope this helps,

Moshe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top