tail -f test.log
Above command will tail the log which runs the process behind the scenes. How can I kill that particular process ?
I can press “Ctrl-Z” on the shell but I am running that command using Java and need to kill that process.
Any help on this will be much appreciated.
thanks
When you start a subprocess with Java you get back a
Processobject corresponding to the running process. You can usedestroy()method on theProcessobject to kill the running command.So you’d start it with:
and kill it with:
If you are just reading new lines added to a file, have you considered doing this natively in Java? Reading the file is pretty straightforward:
You’ll probably want to run this in another
Thread. And unliketail -fthe above code doesn’t handle the file being rewritten from the beginning rather than appended to, but you could fix that.