You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Tenenbaum, Peter G. (ARC-TN)[SETI INSTITUTE] via user" <us...@commons.apache.org> on 2026/02/20 21:36:34 UTC

Obtain process ID of DefaultExecutor process

Hi there —

I was looking for a way to get the process ID of a process that gets started by the DefaultExecutor. From looking at the javadoc, there’s no built-in way to do it.

Google recommends that I create a subclass of DefaultExecutor that overrides the launch() method, such that the Process it returns is interrogated for the PID. DefaultExecutor isn’t final and launch() is protected, so in principle this can be done.

However:

The only public constructor for DefaultExecutor is deprecated. The non-deprecated method to instantiate a DefaultExecutor is to use the DefaultExecutor builder, but AFAICT there’s no way to get this builder to return a DefaultExecutor subclass. I could subclass the DefaultExecutor builder, but the DefaultExecutor builder uses a package-private DefaultExecutor constructor, so my subclass of DefaultExecutor builder can’t use that constructor.

In a pinch, I could imagine giving my subclass its own constructor that emulates the package-private one in DefaultExecutor. Unfortunately, this also won’t work: all the instance variables are private and there are no protected setters for them.

It seems like the intent is there to allow users to subclass DefaultExecutor, but in practice the only way to do it appears to be the deprecated public constructor. Am I missing something?

Is there an easier way to get the PID from a DefaultExecutor?

Thanks,
-PT

Re: Obtain process ID of DefaultExecutor process

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Feb 21, 2026 at 9:12 AM Tenenbaum, Peter G. (ARC-TN)[SETI
INSTITUTE] via user <us...@commons.apache.org> wrote:
>
> Hi there —
>
> I was looking for a way to get the process ID of a process that gets started by the DefaultExecutor. From looking at the javadoc, there’s no built-in way to do it.
>
> Google recommends that I create a subclass of DefaultExecutor that overrides the launch() method, such that the Process it returns is interrogated for the PID. DefaultExecutor isn’t final and launch() is protected, so in principle this can be done.
>
> However:
>
> The only public constructor for DefaultExecutor is deprecated. The non-deprecated method to instantiate a DefaultExecutor is to use the DefaultExecutor builder, but AFAICT there’s no way to get this builder to return a DefaultExecutor subclass. I could subclass the DefaultExecutor builder, but the DefaultExecutor builder uses a package-private DefaultExecutor constructor, so my subclass of DefaultExecutor builder can’t use that constructor.
>
> In a pinch, I could imagine giving my subclass its own constructor that emulates the package-private one in DefaultExecutor. Unfortunately, this also won’t work: all the instance variables are private and there are no protected setters for them.
>
> It seems like the intent is there to allow users to subclass DefaultExecutor, but in practice the only way to do it appears to be the deprecated public constructor. Am I missing something?
>
> Is there an easier way to get the PID from a DefaultExecutor?

Hello PT,

Have you tried registering an ExecuteWatchdog with a DefaultExecutor?
It accepts a Process that you can query.

Gary

>
> Thanks,
> -PT

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org