linux ps 命令

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值