Prerequisites
Before checking processes on your Linux system, ensure you have:
- A Linux distribution installed on your machine.
- Access to a terminal or command-line interface.
- Basic understanding of navigating the terminal.
Understanding Linux Processes
A process represents a running instance of a program or command on your system.
Each application you open creates at least one process. For example, launching a web browser initiates a process that continues until you close the application.
Commands executed in the terminal also generate processes. These terminate once the command completes or you stop it manually.
How to Check Linux List Processes Using the ps Command
Use the ps command to display currently running processes. This command shows process status information in real-time.
Run the basic command:
$ ps
This displays processes for your current shell with four columns:
- PID shows the unique process identifier.
- TTY indicates the terminal type.
- TIME displays total CPU usage.
- CMD shows the command that started the process.
View all running processes with detailed information:
$ ps aux
The a option displays processes from all users. The u option shows user-oriented format. The x option includes processes without a terminal.
This command outputs eleven columns:
- USER identifies the process owner.
- PID provides the process ID.
- %CPU shows CPU usage percentage.
- %MEM displays memory usage percentage.
- VSZ indicates virtual memory size in kilobytes.
- RSS shows resident set size.
- TTY displays the controlling terminal.
- STAT reveals process state.
- START shows when the process started.
- TIME displays CPU time used.
- COMMAND shows the full command.
man ps to access the complete manual with all available options and detailed explanations.
How to Check Linux List Processes Using the top Command
The top command provides a dynamic real-time view of running processes.
Launch the command:
$ top
This displays processes sorted by resource usage. The interface updates automatically every three seconds by default.
Key information includes:
- PID for process identification.
- USER showing who runs the process.
- PR indicating scheduling priority.
- NI displaying nice value.
- VIRT showing virtual memory usage.
- RES indicating physical memory usage.
- S revealing process status (running, sleeping, idle).
- %CPU showing CPU consumption.
- %MEM displaying memory usage.
- COMMAND showing the process name.
Press q to exit the top interface.
How to Check Linux List Processes Using the htop Command
The htop command offers an enhanced interactive interface compared to top.
Install htop if not already available:
$ sudo apt update && sudo apt install htop
For Red Hat-based systems:
$ sudo yum install htop
Launch htop:
$ htop
This displays a color-coded interface with processes sorted by CPU usage. You can scroll through the list, search for specific processes, and manage them interactively.
The interface includes mouse support for easier navigation. You can click on processes to select them and use keyboard shortcuts for management tasks.
How to Filter Process Lists
Combine commands with pipes to filter results.
Display output one page at a time:
$ ps aux | less
Search for a specific process:
$ ps aux | grep firefox
This returns only lines containing the specified term.
Use pgrep to find process IDs by name:
$ pgrep chrome
This outputs the PID of matching processes without additional details.
How to Terminate Running Processes
Stop a process using its PID:
$ kill 1234
Replace 1234 with the actual process ID.
Force termination with the -9 option:
$ kill -9 1234
Kill processes by name:
$ pkill firefox
This terminates all processes matching the specified name.
kill -9 forces immediate termination without allowing the process to clean up. Use this only when normal termination fails.
Conclusion
Monitoring processes helps maintain system health and troubleshoot performance issues.
The ps command provides snapshots of current processes. The top command offers real-time monitoring. The htop command delivers an interactive interface for easier management.
Combine these tools with grep and pipes to filter results effectively. Use kill commands to terminate unresponsive processes when necessary.
Check the manual pages for each command to explore additional options and capabilities.
FAQs
Use the top command to view processes in real-time. It automatically refreshes every three seconds and displays CPU and memory usage dynamically.
The ps aux command displays all running processes from all users with detailed information including CPU usage, memory consumption, and process states.
Use ps aux | grep processname to search for specific processes. Alternatively, use pgrep processname to get only the process IDs.
htop provides a more user-friendly interface with color coding, mouse support, and easier navigation. However, it requires separate installation unlike the built-in top command.
Run top or htop to see processes sorted by CPU usage. The highest consumers appear at the top of the list automatically.
