1
2
3
4
5 package oshi.util.platform.unix.openbsd;
6
7 import java.util.List;
8
9 import oshi.annotation.concurrent.ThreadSafe;
10 import oshi.util.ExecutingCommand;
11 import oshi.util.ParseUtil;
12
13
14
15
16 @ThreadSafe
17 public final class FstatUtil {
18 private FstatUtil() {
19 }
20
21
22
23
24
25
26
27 public static String getCwd(int pid) {
28 List<String> ps = ExecutingCommand.runNative("ps -axwwo cwd -p " + pid);
29 if (ps.size() > 1) {
30 return ps.get(1);
31 }
32 return "";
33 }
34
35
36
37
38
39
40
41 public static long getOpenFiles(int pid) {
42 long fd = 0L;
43 List<String> fstat = ExecutingCommand.runNative("fstat -sp " + pid);
44 for (String line : fstat) {
45 String[] split = ParseUtil.whitespaces.split(line.trim(), 11);
46 if (split.length == 11 && !"pipe".contains(split[4]) && !"unix".contains(split[4])) {
47 fd++;
48 }
49 }
50
51 return fd - 1;
52 }
53 }