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

To get Lyrics on Spotify Music – Install Lyricfier on Ubuntu

In this post, we will show you how to install lyricfier on Ubuntu to enable you get Lyrics on Spotify Music. Spotify once...
12/02/2020

How to Install Jenkins with Docker on Ubuntu 18.04

What is Docker? Docker is a free and open source software tool that can be used to pack, ship and run any application as...
29/12/2020

How to Access VirtualBox 6 VMs Remotely

VirtualBox is an open source virtualization platform. It is an alternative to VMware Workstation Pro, VMware Player and...
29/12/2020
Bài Viết

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

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024