diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-04-01 14:52:42 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-04-01 16:34:21 +0200 |
commit | cad3a232a35439d7b74ed25fe298c674b1fee2af (patch) | |
tree | 9650ad5529a2e34825413064cabf704552ea9591 /jdisc_core | |
parent | c80b9a89029ed2e4c62cb288750ca02b2c3ef84c (diff) |
Use ProcessHandle to get process id
Diffstat (limited to 'jdisc_core')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/ConsoleLogListener.java | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ConsoleLogListener.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ConsoleLogListener.java index e60c058f578..092c2361156 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ConsoleLogListener.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ConsoleLogListener.java @@ -1,17 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.core; +import com.yahoo.net.HostName; import org.osgi.service.log.LogEntry; import org.osgi.service.log.LogListener; -import java.io.File; -import java.io.IOException; import java.io.PrintStream; -import java.lang.management.ManagementFactory; -import com.yahoo.net.HostName; /** - * @author <a href="mailto:vikasp@yahoo-inc.com">Vikas Panwar</a> + * @author Vikas Panwar */ class ConsoleLogListener implements LogListener { @@ -71,31 +68,7 @@ class ConsoleLogListener implements LogListener { } static String getProcessId() { - // platform independent - String jvmName = ManagementFactory.getRuntimeMXBean().getName(); - if (jvmName != null) { - int idx = jvmName.indexOf('@'); - if (idx > 0) { - try { - return Long.toString(Long.valueOf(jvmName.substring(0, jvmName.indexOf('@')))); - } catch (NumberFormatException e) { - // fall through - } - } - } - - // linux specific - File file = new File("/proc/self"); - if (file.exists()) { - try { - return file.getCanonicalFile().getName(); - } catch (IOException e) { - return null; - } - } - - // fallback - return null; + return Long.toString(ProcessHandle.current().pid()); } static String getHostname() { |