Using ps command on linux

29/12/2020
Chưa phân loại
The command “ps” will show the processes status as snapshot. In contrast with Microsoft Windows which shows processes status in live view. In Linux, if we want a live view of the processes we need to use the command top which we won’t explain in this tutorial limited to ps.

Let’s try to run ps without any additional parameter just by running:

ps

As we can see we have 4 columns:

PID: Process ID, shows the process identification number.

TTY: Identifies the terminal from which the process was executed.

TIME: Shows the processor’s time occupied by the program.

CMD: Shows the command used to launch the process.

The ps default output without parameters as you can see will only list the processes executed by root.

If we want to check the processes ran by every user then run:

ps -a

Now we can see the processes executed by all users.  Usually when we use the command ps we add parameters like -a, -x and -u.

While -a lists processes started by all users, -x also lists processes started at boot like daemons, the parameter -u will add columns with additional information on each process:

ps -axu

We can see now all processes, executed by all users, by the system itself and we also got additional information on each process:

USER: Specifies the user who executed the program.

PID: Process ID, shows the process identification number.

CPU%: The processor % used by the process.

MEME%: The memory % used by the process.

VSZ: The virtual size in kbytes.

RSS: In contrast with the  virtual size, this shows the real memory used by the process.

TTY: Identifies the terminal from which the process was executed.

STATE: Shows information on the process’ state just as it’s priority, by running “man ps” you can see codes meaning.

START: Show when the process has started.

TIME: Shows the processor’s time occupied by the program.

CMD: Shows the command used to launch the process.

To list the processes executed by a specific user you can run:

ps -U username

After we understood how to use ps to show processes, let’s check how to stop them.

In Linux the command kill is the one used to stop processes. We can run “kill PIDNUMBER” to stop a process:

As you can see, I killed a process started by Gimp, but if we run ps -axu again we’ll see Gimp is still running:

What we need to do to assure the program’s closure is to kill all it’s processes, including parent processes, we can do it by adding the parameter -9:

kill -9 PIDNUMBER

As you can see this time the process was killed, since I tried to kill it twice and the second time the system told me the process wasn’t available, we can run ps -axu again to be sure:

 The command killall can be used to kill all processes associated with a program’s name:

As you can see in the image above LibreOffice is running now, let’s see what happens when I run:

killall soffice.bin

 
Let’s check ps -axu again:


As we can see LibreOffice was closed.

I hope you found this article useful to manage Linux processes. Keep following us on LinuxHint for more tips and updates on Linux.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Understanding The Dockerfile

You’ll agree with me that the impact Docker is having on the world of technology is massive. It is saving software developers...
29/12/2020

[CentOS 8] Phiên bản các gói phần mềm phổ thông trên CentOS 8

CentOS 8 đã ra mắt vào ngày 24.09.2019 và điều mà mình chú ý hơn cả là các gói phần mềm phổ thông...
30/12/2020

Installing PostgreSQL on CentOS 8

In this article, I am going to show you how to install PostgreSQL database and how to do basic PostgreSQL CRUD operations...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ảo Hóa & Cloud
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ceph
04/04/2025