Linux

Linux ps Command with Examples

Linux ps Command with Examples

ps stands for Process Status. The Linux ps command is used to display information about currently running processes on a system. It is one of the most useful commands for Linux administrators, developers, and software testers when troubleshooting applications, identifying process IDs (PIDs), and checking whether a server or application is running.

For example, when working with application servers such as JBoss or WildFly, we can use the ps command to find the process ID of the server.

The ps command provides a snapshot of the processes that are currently running on a Linux system. It can display details such as:

  • Process ID (PID)
  • Parent Process ID (PPID)
  • User who started the process
  • CPU usage
  • Memory usage
  • Process start time
  • Command used to start the process

Unlike interactive commands such as top and htop, ps normally displays a static snapshot of processes at the time the command is executed.

Syntax of ps Command

$ ps [options]

The behavior and output of ps can be changed by using different options.

Basic ps Command

Running ps without any options displays processes associated with the current terminal.

$ ps

A typical output may look like:

PID TTY          TIME CMD
2451 pts/0    00:00:00 bash
3187 pts/0    00:00:00 ps

Here, PID is the unique process ID, TTY indicates the terminal, TIME shows CPU time consumed, and CMD shows the command associated with the process.

Display All Processes

One of the most common uses of ps is to display processes running on the system.

$ ps -e

The -e option selects every process.

Another commonly used form is:

$ ps -A

The -A option also displays all processes.

Display Detailed Process Information

The following command displays processes with additional information:

$ ps -ef

The -e option selects all processes, while -f displays the processes in a full-format listing.

Example output:

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 10:15 ?        00:00:03 /sbin/init
user      2451  2400  0 10:30 pts/0    00:00:00 bash
user      3187  2451  0 10:35 pts/0    00:00:00 ps -ef

Find the Process ID of JBoss or WildFly

The ps command is particularly useful for finding the process ID of application servers such as JBoss or WildFly.

For example:

$ ps -aef | grep wildfly

The command combines ps with grep to search for processes containing the word wildfly.

Example output:

jboss    12584     1  0 10:20 ?  00:02:15 /opt/wildfly/bin/standalone.sh
jboss    12602 12584  0 10:20 ?  00:05:42 java -D[Standalone] -jar wildfly.jar
user     13010  2451  0 10:40 pts/0 00:00:00 grep wildfly

In this example, 12584 and 12602 are process IDs associated with the WildFly server processes. The PID can then be used with other Linux commands for monitoring or process management.

Understanding ps -aef

The command below is widely used by Linux engineers:

$ ps -aef

It provides a full-format listing of processes from across the system.

Important columns include:

Column Description
UID User who owns the process
PID Process ID
PPID Parent Process ID
C CPU utilization information
STIME Start time of the process
TTY Controlling terminal
TIME Total CPU time used
CMD Command used to start the process

Search for a Specific Process

We can combine ps with the grep command to search for a particular application or service.

$ ps -ef | grep java

This command lists processes whose command line contains the word java.

For example, it can help identify Java-based applications, application servers, or background services.

Find a Process by User

To display processes started by a particular user, use the -u option:

$ ps -u jboss

This is useful when multiple users are running applications on the same Linux server.

Display Processes in User-Oriented Format

The following command provides a more readable process listing:

$ ps aux

The aux format is commonly used to inspect processes across the system.

Example:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  225000  12000 ?      Ss   10:15   0:03 /sbin/init
jboss    12602  4.2  8.5 2500000 680000 ?      Sl   10:20   5:42 java
user     14500  0.0  0.0   10000   3000 pts/0  S+   10:45   0:00 ps aux

Display a Process by PID

When you already know the process ID, you can use the -p option:

$ ps -p 12602

You can also request a full-format listing for a specific PID:

$ ps -fp 12602

This is helpful when you want detailed information about one specific process.

Display Parent and Child Processes

The --forest option can be used with ps to visualize parent-child relationships between processes.

$ ps -ef --forest

This can make it easier to understand how an application was started and which processes were created by a parent process.

Sort Processes by CPU Usage

To identify processes consuming significant CPU resources, you can sort the output by CPU usage.

$ ps aux --sort=-%cpu

The process using the highest CPU percentage appears near the top of the output.

Sort Processes by Memory Usage

Similarly, processes can be sorted by memory consumption:

$ ps aux --sort=-%mem

This is useful when investigating applications that consume excessive memory.

Show Process Details with Custom Columns

The -o option allows you to specify the columns that should be displayed.

$ ps -eo pid,ppid,user,%cpu,%mem,cmd

This command displays process ID, parent process ID, user, CPU usage, memory usage, and command.

Find Java Application Processes

Since many enterprise applications run on the Java Virtual Machine, Linux engineers often use:

$ ps -ef | grep java

This can help identify Java processes associated with applications such as JBoss, WildFly, Tomcat, Spring Boot applications, and other Java services.

Ignore the grep Process

When using commands such as:

$ ps -ef | grep wildfly

the grep wildfly command itself may appear in the results. A common alternative is:

$ ps -ef | grep '[w]ildfly'

This pattern helps avoid displaying the grep command itself in the result.

ps Command for Software Testers

The ps command is also useful for software testers and automation engineers, especially when testing applications deployed on Linux servers.

For example, testers can use ps to:

  • Verify that an application server is running.
  • Find the PID of a Java, JBoss, or WildFly process.
  • Check whether multiple unwanted processes are running.
  • Investigate applications that consume high CPU or memory.
  • Support troubleshooting during deployment and test execution.
  • Find a process before stopping or restarting a service.

ps vs top vs htop

Command Purpose
ps Displays a snapshot of running processes
top Provides real-time process and resource monitoring
htop Interactive and user-friendly process monitoring

Useful Linux ps Commands

Command Use
ps Show processes associated with the current terminal
ps -e Show all processes
ps -ef Show all processes in full format
ps aux Show detailed process information
ps -u username Show processes for a specific user
ps -p PID Show information for a specific process
ps -fp PID Show detailed information for a specific PID
ps -ef | grep wildfly Find WildFly or JBoss-related processes
ps aux --sort=-%cpu Sort processes by CPU usage
ps aux --sort=-%mem Sort processes by memory usage

Example: Finding and Stopping a WildFly Process

Suppose a WildFly server is running on a Linux machine and you need to find its PID.

$ ps -aef | grep wildfly

After identifying the appropriate PID, such as 12602, you can inspect it:

$ ps -fp 12602

Once you have confirmed that it is the correct process, a process-management command such as kill can be used according to your system’s operational procedures:

$ kill 12602

Care should be taken when stopping processes, especially on production systems.

Conclusion

The Linux ps command is a fundamental tool for checking and troubleshooting running processes. It helps engineers quickly identify process IDs, inspect application processes, analyze CPU and memory usage, and verify that services such as JBoss and WildFly are running.

One of the most useful commands to remember is:

$ ps -aef | grep wildfly

By combining ps with commands such as grep, Linux users can efficiently search for specific processes and perform day-to-day system administration and troubleshooting tasks.

Frequently Asked Questions (FAQ)

What does ps mean in Linux?

ps stands for Process Status and is used to display information about running processes.

How do I find the PID of a process in Linux?

You can use a command such as ps -ef | grep process-name to locate the process and identify its PID.

How do I find the WildFly process ID?

Use ps -aef | grep wildfly and check the PID column in the output.

What is the difference between ps -ef and ps aux?

Both commands provide detailed process information, but they use different option conventions. ps -ef uses the System V-style options, while ps aux uses BSD-style options and commonly displays CPU and memory percentages.

Is ps a real-time monitoring command?

No. ps normally displays a snapshot of processes. For continuous interactive monitoring, commands such as top or htop are more suitable.