1

I'm looking for a good way to work with processes (in Windows, but probably in Linux too).

Is there any pure java solution?

Or at least a cross platform library that does all the parsing?

I need to:

  • see if program is running
  • send a "close" signal to it (not kill)
  • start it (that's probably the only thing I got solved)

All solutions I find say I should parse a tasklist in Windows.

But that's a real pain in the butt.

Anyone done something like this?

Serge Vinogradoff
  • 2,012
  • 2
  • 23
  • 38
  • Wouldn't this help? http://stackoverflow.com/questions/4912282/java-tool-method-to-force-kill-a-child-process?rq=1 – Erik Pragt Jul 08 '13 at 13:45
  • 1
    There is no such thing as a "close" signal... What do you mean exactly? – fge Jul 08 '13 at 13:45
  • Try to use [JSVC](http://commons.apache.org/proper/commons-daemon/jsvc.html) – Damian0o Jul 08 '13 at 13:46
  • fge: in Windows when you click "close" button - it tells program to close. so the program does all "before-close" and "after-close" callbacks and then closes. pretty sure it exists – Serge Vinogradoff Jul 08 '13 at 13:48
  • Erik: this requires manually writing the actual command line commands. Isn't there a more abstract way? – Serge Vinogradoff Jul 08 '13 at 13:50
  • 1
    Damian0o: how exactly JSVC can help? it seems it just gives root privileges, no? – Serge Vinogradoff Jul 08 '13 at 13:56
  • possible duplicate of [Is it possible to end a process nicely in a Java application?](http://stackoverflow.com/questions/955248/is-it-possible-to-end-a-process-nicely-in-a-java-application) – Enno Shioji Jul 08 '13 at 13:58

1 Answers1

0

On linux : jps will provide you a list of only Java processes running including pid or ps -aux | grep '<program name or part of program name> for all the processes and you can then use kill -15 <pid> to kill, which gives a normal shutdown signal.

Check this link for what kill -15 does, if you aren't sure.

On windows: taskkill /pid <pid> or taskkill /im app.exe will gracefully send the shutdown signal to a running pid. jps is valid for windows too and for all process you can try TASKLIST /fi "imagename eq <app>.exe"

SSaikia_JtheRocker
  • 4,933
  • 1
  • 20
  • 39