blob: ec691fe4ac430ce89bf483b08874b4e26b6a4216 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.log;
import static com.yahoo.vespa.defaults.Defaults.getDefaults;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author Bjorn Borud
* @author arnej27959
*
*/
public class Util {
public static String getHostName () {
return getDefaults().vespaHostname();
}
/**
* Emulate the getpid() system call
**/
public static String getPID() {
try {
Process p = Runtime.getRuntime().exec(
new String[] {"perl", "-e", "print getppid().\"\\n\";"}
);
BufferedReader r = new BufferedReader(
new InputStreamReader(p.getInputStream(), "UTF-8"));
String line = r.readLine();
p.destroy();
int pid = Integer.parseInt(line);
if (pid > 0) {
return Integer.toString(pid);
}
} catch(Exception e) {
// any problem handled by return below
}
return "-";
}
}
|