Skip to content

Commit f536083

Browse files
hendrikhalkowndeloof
authored andcommitted
JENKINS-49278 Get process list within containers by explicitly specifying ps output.
1 parent a510e85 commit f536083

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNu
135135
}
136136

137137
public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException {
138-
LaunchResult result = launch(launchEnv, false, "top", containerId);
138+
LaunchResult result = launch(launchEnv, false, "top", containerId, "-eo", "pid,comm");
139139
if (result.getStatus() != 0) {
140140
throw new IOException(String.format("Failed to run top '%s'. Error: %s", containerId, result.getErr()));
141141
}
@@ -146,12 +146,10 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
146146
in.readLine(); // ps header
147147
while ((line = in.readLine()) != null) {
148148
final StringTokenizer stringTokenizer = new StringTokenizer(line, " ");
149-
if (stringTokenizer.countTokens() < 4) {
149+
if (stringTokenizer.countTokens() < 2) {
150150
throw new IOException("Unexpected `docker top` output : "+line);
151151
}
152152
stringTokenizer.nextToken(); // PID
153-
stringTokenizer.nextToken(); // USER
154-
stringTokenizer.nextToken(); // TIME
155153
processes.add(stringTokenizer.nextToken()); // COMMAND
156154
}
157155
}

0 commit comments

Comments
 (0)