Reputation: 10057
When running the ps
command I get an output like this:
[nick]$ ps
PID TTY TIME CMD
3287 pts/3 00:00:00 bash
12308 pts/3 00:00:00 ps
19544 pts/3 00:00:00 STS
19548 pts/3 00:45:25 java
19753 pts/3 00:04:10 java
21149 pts/3 00:15:25 java
This doesn't help me that much because I don't know what each Java process really is. Running ps T
gives more information, but now there's too much!
[nick]$ ps T
PID TTY STAT TIME COMMAND
3287 pts/3 Ss 0:00 bash
12319 pts/3 R+ 0:00 ps T
19544 pts/3 S 0:00 /home/nick/springsource/sts-3.0.0.RELEASE/STS
19548 pts/3 Sl 45:25 /usr/lib/jvm/java-6-openjdk-amd64/bin/java -Dosgi.requiredJavaVersion=1.5 -Xms256m -Xmx1536m -XX:MaxPermSize=512m -jar /home/nick/springsource/sts-3.0.0.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -os linux -w......
19753 pts/3 Sl 4:10 /usr/lib/jvm/java-6-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:48135 -Dcatalina.base=/home/nick/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3 -Dcatalina.home=/home/nic......
21149 pts/3 Sl 15:25 /usr/lib/jvm/java-6-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:57346 -Dcatalina.base=/home/nick/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp5 -Dcatalina.home=/home/nic......
Is there a way of just displaying the filename of the Java package or class being run? Something like this:
[nick]$ ps
PID TTY TIME CMD
3287 pts/3 00:00:00 bash
12308 pts/3 00:00:00 ps
19544 pts/3 00:00:00 STS
19548 pts/3 00:45:25 java abc.jar
19753 pts/3 00:04:10 java def.java
21149 pts/3 00:15:25 java ghi.jar
If this can't be done with ps
arguments, is there a way of achieving it with grep
?
Upvotes: 1
Views: 2964
Reputation: 72639
No, not with ps. It's either all args or none (modulo truncation of the arglist). But what about filtering the long ps output to leave just what you want? There's a lot you can do with sed, awk, perl, cut and others. The manuals have all the details.
Example: To print fields 1 through 4 and the last field, use
ps T | awk '{print $1, $2, $3, $4, $NF}'
Note how this matches the Unix philosophy of having one tool do one thing well: ps prints process information, while awk picks the fields you want.
Upvotes: 4
Reputation: 12837
What you are looking for is probably jps
cli utility or graphical jconsole
.
Upvotes: 1