CodeNewbie Community 🌱

Cover image for Efficiently Managing Processes with the ps Command in Linux
k1lgor
k1lgor

Posted on

Efficiently Managing Processes with the ps Command in Linux


Introduction

The ps command is a powerful tool in Linux that allows you to monitor and manage processes on your system. Whether you need to identify a specific process, check the resource usage of a program, or kill a process that's misbehaving, the ps command has you covered.

Using the ps Command

At its simplest, the ps command allows you to view information about the processes running on your system. For example, you can use the ps command with no options to display a list of all the processes running on your system:

ps

Enter fullscreen mode Exit fullscreen mode

Image 1

The above command will display a list of all the processes currently running on your system. By default, the ps command will display the process ID (PID), the terminal associated with the process, the CPU usage, and the command that started the process

Options and Customization

While the basic ps command is useful, there are many options and customization features that you can use to tailor the output to your specific needs. For example, you can use the -e option to display information about all processes on the system, regardless of who owns them:

ps -e
Enter fullscreen mode Exit fullscreen mode

Image 2

Another useful option is the -f option, which displays a more detailed output that includes the UID, PPID, C, STIME, TTY, and TIME fields:

ps -f
Enter fullscreen mode Exit fullscreen mode

Image 3

Tips and Tricks

  • You can use the grep command to search for specific processes. For example, to search for all processes containing the word "chrome", you can use the following command:
ps -ef | grep brave

Enter fullscreen mode Exit fullscreen mode

Image 4

  • You can use the kill command to terminate a process. For example, to kill a process with a specific PID, you can use the following command:
kill PID
Enter fullscreen mode Exit fullscreen mode

Image 5

And you choose the PID number.

  • Show all processes with full information:
ps -ef
Enter fullscreen mode Exit fullscreen mode

Image 6

  • Show all processes with full information and a tree-like format:
ps -ejH
Enter fullscreen mode Exit fullscreen mode

Image 7

  • Show all processes with full information and a BSD-style format:
ps axo pid,tt,user,fname,tmout,f,wchan
Enter fullscreen mode Exit fullscreen mode

Image 8

  • Show all processes with full information and display the username and start time:
ps -eo user,pid,ppid,c,start_time,cmd
Enter fullscreen mode Exit fullscreen mode

Image 9

  • Show all processes with full information and display the threads for each process:
ps -eLf
Enter fullscreen mode Exit fullscreen mode

Image 10

  • Show all processes with full information and display the start time and elapsed time for each process:
ps -eo pid,comm,lstart,etime
Enter fullscreen mode Exit fullscreen mode

Image 11

  • Show all processes with full information and sort by memory usage (descending):
ps -e --sort=-rss
Enter fullscreen mode Exit fullscreen mode

Image 12

  • Show all processes with full information and display only the processes owned by a specific user:
ps -u username
Enter fullscreen mode Exit fullscreen mode

Image 13

  • Show all processes with full information and display only the processes with a specific name:
ps -C program_name
Enter fullscreen mode Exit fullscreen mode

Image 14

  • Show all processes with full information and display only the processes with a specific PID:
ps -p PID
Enter fullscreen mode Exit fullscreen mode

Image 15

  • You can use the top command to view a dynamic real-time display of the processes running on your system.

Conclusion

The ps command is a powerful and essential tool in Linux for monitoring and managing processes. With its simple syntax and powerful options, you can quickly identify, monitor, and manage processes on your system. Whether you're a system administrator, developer, or power user, the ps command is a must-know tool for efficient Linux management.

Thank you for reading 🧑‍💻

Stay tuned for more 🚀

✌️ and logout


Buy Me A Coffee

Top comments (0)