class ProcessHelper {

    void doEndProcess(Process process, boolean checkTerminatedProcess) {

        // borrowed from java 8 Process#isAlive()
        // it has the same caveat as isAlive, which means that it will not detect process termination
        // until the actual process has terminated, for example right after a call to Process#destroy().
        // in that case, ignoring the process actual status is relevant.
        boolean terminated = !checkTerminatedProcess;
        if (checkTerminatedProcess) {
            try {
                process.exitValue();
                terminated = true;
            } catch (IllegalThreadStateException e) {
                terminated = false;
            }
        }

        if (terminated) {
            Span span = inFlightSpans.remove(process);
            if (span != null) {
                span.end();
            }
        }
    }

      ProcessHelper(WeakConcurrentMap<Process, Span> inFlightSpans);

}