use of es.bsc.compss.nio.worker.exceptions.InvalidMapException in project compss by bsc-wdc.
the class BindToMap method getLsCpuOutput.
private static String getLsCpuOutput() throws InvalidMapException {
// **************************************************************************************
// Get LSCPU output
// **************************************************************************************
String cmdOutput = null;
ProcessBuilder pb = new ProcessBuilder("lscpu");
try {
pb.environment().remove(Tracer.LD_PRELOAD);
Process process = pb.start();
// Disable inputs to process
process.getOutputStream().close();
// Wait and retrieve exit value
int exitValue = process.waitFor();
if (exitValue != 0) {
throw new InvalidMapException("ERROR: LSCPU command failed with exitValue " + exitValue);
}
// Retrieve command output
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (IOException ioe) {
throw new InvalidMapException("ERROR: Cannot retrieve LSCPU command output", ioe);
}
cmdOutput = sb.toString();
} catch (IOException ioe) {
throw new InvalidMapException("ERROR: Cannot start LSCPU ProcessBuilder", ioe);
} catch (InterruptedException ie) {
throw new InvalidMapException("ERROR: LSCPU command interrupted", ie);
}
return cmdOutput;
}
Aggregations