I'm looking for some simple tasks like listing all the running process of a user, or kill a particular process by pid etc. Basic unix process management from Java. Is there a library out there that is relatively mature and documented? I could run a external command from the JVM and then parse the standard output/error but that seems like a lot of work and not robust at all. Any suggestions?
You will need to roll your own solution I think. Killing an external process created using the Process
APIs can be done using Process.destroy()
. (But note that destroy()
as implemented on Linux / Unix does a "soft" kill, not a SIGKILL
, so the external process may be able to avoid being killed.)
Anything beyond that is non-portable.
/proc
file system.Process
. It depends on whether your management functionality requires use of syscalls that are not available to a "pure" Java program.If you go down the JNI + native library route, beware that native pointer problems and native threading issues can kill your JVM. You may also need to deal with building and distributing the native library for multiple architectures, etc. Also beware that the internal data structures are liable to be different for different JVM platforms, releases, etc, and that they are liable to change without notice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With