String (int pid) { String procPath = "/proc/" + pid + "/cwd"; try { File dir = Paths.get(procPath).toRealPath().toFile(); if (dir.isDirectory()) { return dir.getAbsolutePath(); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot resolve cwd from " + procPath + ", fallback to lsof -a -d cwd -p " + pid, e); } } return null; }