Process trees and termination (original) (raw)

Peter Levart peter.levart at gmail.com
Thu Jun 26 08:55:09 UTC 2014


On 06/26/2014 12:05 AM, David M. Lloyd wrote:

On 06/25/2014 04:52 PM, roger riggs wrote:

Hi,

The next step for JEP 102, Process API Updates is to provide an API to enumerate the hierarchy of processes and to be able to terminate a process tree. This draft javadoc <http://bussund0416/%7Erriggs/pdoc/>update [1] includes: - ProcessHandle class to provide handles to processes, their children, parent, process id and liveness - Process extends ProcessHandle and inherits the new behaviors - Method destroyProcessTree() terminates a process tree Additional functions related to termination and information about processes will be added in a later update. Comments appreciated, Roger I still have a not-great feeling about the lack of atomicity inherent in these operations. At least when you're dealing with direct child processes (on UNIX-likes), there is some measure of control, in that a process is zombified until reaped by wait() and friends. Also I have a much higher level of concern about destroyProcessTree(), which I don't think has any place in this API. Control of any process belongs solely with their parent (or PID 1), in my opinion. Those concerns aside, what about making the allChildren() and allProcesses() methods lazy in some way? Hi Roger, David,

The following expression: ProcessHandle.current().children() would therefore return just canonicalized Process objects (unless some native code embedded in the JVM process started sub-processes too).

If returning canonicalized Process objects from factory methods is not desirable (some part of the program could mess with Input/Output streams of Process-es it did not have access to before), then perhaps ProcessHandle representing a process created by ProcessBuilder API would just have an internal private reference to the Process object to which it would forward method invocations...

public abstractProcessHandle <http://cr.openjdk.java.net/%7Erriggs/ph-apidraft/java/lang/ProcessHandle.html> destroyForcibly()

Kills the process. The process represented by this |ProcessHandle| object is forcibly terminated. If the process is not alive no action is taken.

Note: The process may not terminate immediately. i.e. |isAlive()| may return true for a brief period after |destroyForcibly()| is called. This method may be chained to |waitFor()| if needed.

...the method has a co-variant return type and there's no waitFor() method on the ProcessHandle. Why not? If ProcessHandle is a (or delegates to) Process then it could use it's waitFor(), if it is just a "foreign" ProcessHandle it could be implemented as a poll-ing wait for the isAlive() to return false...

Regards, Peter



More information about the core-libs-dev mailing list