Adding a new method getPID() in MavenSession

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Adding a new method getPID() in MavenSession

Tibor Digana-2
Hi all,

I want to ask for your opinion about adding *getPID *method in MavenSession.

With Michael Osipov we talked about ensuring PID observed from Maven
We need to read PID of Maven process within Surefire plugin. We have
several alternatives however only Java 9 introduced standard API providing
the PID.

For me it would be fine to get the PID from MavenSession rather than
discovering it in an individual Maven plugin since it is Maven's
information and all plugins may read it too.

For Java < 9 the JNA call can read PID. We found sources at Hudson which
may help us

As a standard Java way we can call Java 9 Jigsaw code:
long pid = ProcessHandle.current().pid();

Linux standard way is to read the link on file system
String pid = new File("/proc/self").getCanonicalFile().getName()

Non-standard simplistic way
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]

Bad fact on JMX is the startup cca 50 - 80 milliseconds.