diff --git a/frontend/server/src/main/java/org/pytorch/serve/wlm/WorkerThread.java b/frontend/server/src/main/java/org/pytorch/serve/wlm/WorkerThread.java index 793a2c1d1b..27af027c99 100644 --- a/frontend/server/src/main/java/org/pytorch/serve/wlm/WorkerThread.java +++ b/frontend/server/src/main/java/org/pytorch/serve/wlm/WorkerThread.java @@ -120,12 +120,16 @@ public String getGpuUsage() { try { // TODO : add a generic code to capture gpu details for different devices instead of // just NVIDIA - process = - Runtime.getRuntime() - .exec( - "nvidia-smi -i " - + gpuId - + " --query-gpu=utilization.gpu,utilization.memory,memory.used --format=csv"); + ProcessBuilder pb = + new ProcessBuilder( + "nvidia-smi", + "-i", + String.valueOf(gpuId), + "--query-gpu=utilization.gpu,utilization.memory,memory.used", + "--format=csv"); + + // Start the process + process = pb.start(); process.waitFor(); int exitCode = process.exitValue(); if (exitCode != 0) {