Java: Get a process given a pid

前端 未结 4 1919
悲哀的现实
悲哀的现实 2020-12-16 16:07

Say I have a current running process known, how can I turn this into a Process object in Java? The process is already running, so I don\'t want to spawn off another one, I j

4条回答
  •  天命终不由人
    2020-12-16 16:33

    I don't think this is possible using only the builtin library. AFAIK, it is already non-trivial to get the running process' own PID (see the feature request and alternate mechanisms).

    A quick look at the java.lang.Process class shows that you could go about writing your custom implementation of java.lang.Process using JNI and native code. Your custom class could then implement extra methods, such as the one in your question.

提交回复
热议问题