Follow “Operations Interview Insights”
Click the “⭐ Star” on the left to receive immediate updates on articles
In Linux systems, both ps -ef | grep java and jps -l are methods used to view Java processes, but they have some important differences.
ps -ef | grep java
Command: ps is a command used to display the current status of processes in the system.
Options: Displays all processes.
Option: Full-format display, including more information such as UID, PID, PPID, C, STIME, TTY, TIME, and CMD, etc.
| Pipe: Passes the output of ps -ef to the grep command.
grep java: Filters the output of ps -ef to show lines containing “java”.
Advantages:
Can display all processes containing “java”, not just Java Virtual Machine (JVM) processes.
Can show more process information.
Can be combined with other commands for more complex filtering and processing.
Disadvantages:
Requires manual filtering of output, which may include processes unrelated to Java (e.g., other processes with “java” in their filename or command line arguments).
Output format is not uniform and depends on the output format of the ps command.
jps -l
The jps command: jps is the Java Virtual Machine Process Status Tool, specifically designed to display the status of JVM processes.
-l option: Displays the fully qualified name of the main class or the full path of the JAR file.
Advantages:
Specifically designed for Java processes, only shows JVM processes.
Uniform output format, easy to parse.
Can directly display the fully qualified name of the main class or the full path of the JAR file, making it easier to identify specific Java applications.
Disadvantages:
Can only display JVM processes, cannot show other processes containing “java”.
Provides less process information compared to ps -ef.
Example
ps -ef | grep java
$ ps -ef | grep java
user 12346 23456 0 12:35 pts/0 00:00:00 grep –color=auto java
user 12345 6789 0 12:34 ? 00:00:01 java -jar myapp.jar
jps -l
$ jps -l
12345 my.package.MainClass
Follow Da Ge for more knowledge
Da Ge has painstakingly compiled an 88-page document of frequently asked technical questions for operations engineers, covering daily Linux operations, Tomcat, Nginx, Keepalived high availability, Docker, Kubernetes, MySQL, Redis, Kafka, system failures, service failures, storage and disk failures, network failures, distributed system failures, and troubleshooting. This is a strong aid for interviews and skill consolidation, and can also help identify gaps in knowledge. Follow the public account and reply with “Interview Questions” to receive it for free.