Linux PS command with examples

As a system administrator, you need to have cutting-edge commands in your hand. One such command we discuss today with examples is the PS command in Linux.

Linux is an excellent choice for those looking for a multitasking and multi-user operating system. Multiple processes can run simultaneously and independently from each other and is exceptionally stable. Whenever we run a program, a new process of that program’s instance will be created and perform the given tasks without disturbing other running programs.

Linux has ps (Process Status) utility for viewing information related to processes running on the system. Using the ps command, you can get processes list, their PIDs, and some different details using other options.

Linux PS command

In this article, we will show you some useful ps commands with examples. Ps provides numerous options for different purposes.

Syntax:

ps <options>

Where <options> is the parameter for various purposes that we will discuss in detail in this article.

1. List Current Shell Processes

You can show the list of processes for the current shell using the ps command, and if no other process is running, it will return the process running the ps command.

$ ps

Example:

show shell processes
show shell processes

The command displays four columns with information:

  • PID: It is a Unique Process ID
  • TTY: Type of terminal user currently logged in
  • TIME: CPU running time in minutes and seconds
  • CMD:  Name of the command which started this process

2. List all Processes

You can display all processes running on the system using the -e operator.

$ ps -e

Example:

show all processes using ps command
show all processes using ps command

You can get additional details of all processes using -f and -F options.

$ ps -f

Example:  -f option provides full-format listing.

show all processes with full format
show all processes with full format

$ ps -F

Example:  -F option provides extra full format listing

show all processes with extra full format
show all processes with additional full format

3. List all Processes for a User

To display all the processes by a user on the system, use the operator.

Syntax:

$ ps -u <UID>

Here <UID> is the User ID or User Name for whom we are listing the processes.

Example:

ps -u tuts

show all processes by User
show all processes by User

4. List all the Processes for a Group

If you want to display all the processes by a group on the system, the g operator comes in handy. Here is the general syntax.

Syntax:

$ ps -g <GID>

Here <GID> is Group ID or Group Name for whom we are listing processes.

Example:

show all processes by Group
show all processes by Group

5. List Processes by the Command Name

Just in case if you needed all the processes of a command on the system, the C operator usage is priceless. Let’s see its syntax and example usage.

Syntax:

$ ps -C <program>

Here <program> is the name of the command.

Example:

show all processes of command
show all processes of command

6. Show the Process Tree

You can retrieve the process in hierarchy or tree fashion using the below command.

$ ps -e -H

Example:

show processes in tree or hierarchy

Alternatively, you can also display the processes in ASCII format using –forest option.

$ ps -e --forest

Example:

show processes in ASCII format
show processes in ASCII format

7. Find the Process PID

Sometime, you may need to find the process ID of a running process. To look for it, you may use the grep command as shown below:

ps -ef | grep thunderbird

Example:

Search process pid
Search process PID

Here 2846 is the process id for the thunderbird program. You can later use this PID to kill this process using the kill command.

kill <process id>

8. Display the Processes of consuming High Memory

The following command is highly valuable for system admins during troubleshooting the system. You can display the processes list in a sorted manner to find out the highest memory usage processes.

ps -eo pid,cmd,%mem,%cpu --sort=-%mem

Example:

display process using high memory
display process using high memory

Conclusion

Those were the various ways to use the ps command in Linux. You can see how useful and essential these commands can be for proper system administration and management. To learn more about these commands usage, you can use the help option in the terminal while in the particular command.

Habib Ahmed
He is a professional writer with more than seven years of experience in the field. He also enjoys technical writing/ manuals, white papers, and scientific presentations.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,241FansLike
391FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

The Ubuntu Cinnamon Remix brings together Linux Mint's Cinnamon desktop with the Ubuntu Core. While some users are welcoming the new flavor of Ubuntu with open arms, others are scratching their heads, wondering where it fits in.
The wait is finally over (almost) for all you Ubuntu fans out there. The latest version of Ubuntu, 20.10 codenamed "Groovy Gorilla," is currently available in the beta version. I have tested out the distro myself, and it is stable enough to take out for a spin.

Installing an updatable Manjaro Linux on a USB Flash Drive

In this tutorial, we will show step by step how to install a Manjaro on a USB flash. For those new to this distro, it is a light-weight distro that is based on Arch Linux. Arch Linux is known for its simplistic approach and is typically made for Linux pros, but Manjaro bridges the gap between user-friendliness and rock-solid performance.

10+ Best Python IDEs for Linux

Python programming language is applied in so many areas of computer technology, i.e., Scripting, GUI development, Website development, Artificial Intelligence (AI), Machine Learning, Data Science, Computer Networking, and Network Automation, and Cyber Security.

13 ways to use the copy command in Linux (with examples)

Being a Linux user, copying files and directories is one of the everyday tasks that you have to carry out. It can be copying a file to make a backup or copy it to another partition, directory, or external storage drive.

What is the difference between Linux and Unix?

When discussing Linux and Unix with average users, it's not uncommon that they will sometimes mistakenly interchange the terms Linux and Unix.  The two are not the same.  Though they share similarities in their overall structures and toolkits, they are decidedly not the same.