linux ps 命令_Linux ps命令教程

linux ps 命令

linux ps 命令

Processes are one of the main parts of the operations systems. All user side even kernel side operations are executed with the process. The process generally created, run, and killed. This life cycle of the process generally the same. During this life cycle, we may need to get more information about processes. ps command is the most used command to list and get information about processes.

流程是操作系统的主要部分之一。 所有用户端甚至内核端操作都与该进程一起执行。 该过程通常是创建,运行和终止的。 这个过程的生命周期大体相同。 在此生命周期中,我们可能需要获取有关流程的更多信息。 ps命令是最常用的命令,用于列出和获取有关进程的信息。

列出当前用户进程 (List Current User Processes)

The process can be listed without providing any option to the ps command. But this will only list current user’s processes and do not list another system, user, or root user processes.

可以列出该进程,而无需为ps命令提供任何选项。 但这只会列出当前用户的进程,而不会列出另一个系统,用户或root用户进程。

$ ps
List Current User Processes
List Current User Processes
列出当前用户进程

BSD语法(BSD Syntax)

ps command is a very universal tool. ps also used other Unix variant operations systems. BSD provides options without a dash. So there is generally no difference but knowing BSD Syntax is beneficial. The following example uses the BSD syntax.

ps命令是一个非常通用的工具。 ps还使用了其他Unix变体操作系统。 BSD提供的选项没有破折号。 因此,通常没有区别,但是了解BSD语法是有益的。 以下示例使用BSD语法。

ps  aux

列出所有进程 (List All Process)

In previous steps, we have listed the processes running on the Linux system just for the current users. But generally, we need to list all processes in a single shot. We can provide the -ax options in order to list all processes.

在前面的步骤中,我们仅列出了当前用户在Linux系统上运行的进程。 但是通常,我们需要一次列出所有进程。 我们可以提供-ax选项以列出所有进程。

$ ps -A
List All Process
List All Process
列出所有进程
  • PID show process ID

    PID显示进程ID

  • TTY show running console

    TTY显示运行控制台

  • TIME  show the used CPU time

    TIME显示所用的CPU时间

  • CMD show the complete command the thread number

    CMD显示完整命令的线程号

将进程列为树(List Processes As Tree)

In the previous example, we have printed all processes in the list format. There is an alternative presentation format named Tree. Tree format is a hierarchical format which will provide visual information about parent and child relationship.

在前面的示例中,我们以列表格式打印了所有进程。 还有一种名为Tree的替代表示格式。 树格式是一种分层格式,它将提供有关父子关系的可视信息。

$ ps -A --forest
List Processes As Tree
List Processes As Tree
将进程列为树

列出流程信息(List Process Info)

While listing processes we can print more information about the process. We will use -u option for this detailed information.

在列出流程时,我们可以打印有关流程的更多信息。 我们将使用-u选项获取此详细信息。

$ ps -A l
List Process Info
List Process Info
列出流程信息
  • UID show the User ID of process

    UID显示进程的用户ID

  • PID shows the process ID

    PID显示进程ID

  • PPID shows the Parent Process ID

    PPID显示父进程ID

  • PRI shows Process nice value

    PRI显示出良好的Craft.io价值

  • STAT shows the current status of the process

    STAT显示流程的当前状态

  • TTY shows the current console number if connected

    TTY显示当前控制台编号(如果已连接)

LEARN MORE  What Is a Motherboard?
了解更多什么是主板?

仅列出特定的命名过程 (List Only Specific Named Process)

While listing processes we may need to filter according to process or command name. Here we will use -C parameter and process name for filter operation.

在列出进程时,我们可能需要根据进程或命令名称进行过滤。 在这里,我们将使用-C参数和进程名称进行过滤操作。

$ ps  -C acpid

仅打印特定的PID过程 (Print Only Specific PID Process)

Another way to filter processes id according to their PID. We can filter by given their PID. We will use the -p option and PID’s in order to filter. In this example, we will filter multiple processes according to their IP address.

根据进程的PID过滤进程ID的另一种方法。 我们可以根据给定的PID进行过滤。 我们将使用-p选项和PID进行过滤。 在此示例中,我们将根据其IP地址过滤多个进程。

$ ps  -p 1331,1773
Print Only Specific PID Process
Print Only Specific PID Process
仅打印特定的PID过程

仅打印特定的用户进程(Print Only Specific User Processes)

Another useful filtering mechanism is filtering processes according to their owners or users. We will use -u option and usernames to filter. In this example, we want to filter username ismail .

另一个有用的过滤机制是根据进程的所有者或用户过滤进程。 我们将使用-u选项和用户名进行过滤。 在此示例中,我们要过滤用户名ismail

$ ps   -u ismail
Print Only Specific User Processes
仅打印特定的用户进程

显示进程线程(Display Threads of Process)

As we know Linux provides threads to make processes more efficient. Threads are created under the processes and complete given work by the parent process. We will use --ppid option in order to list child threads.

众所周知,Linux提供了使进程更高效的线程。 线程是在流程下创建的,并由父流程完成给定的工作。 我们将使用--ppid选项来列出子线程。

$ ps --ppid 1331

根据Cpu使用情况对流程进行排序 (Sort Process According To Cpu Usage)

While list process by default they are sorted with their PID’s. There are alternatives to sort processes. We can sort processes according to t their current CPU usage with --sort=pcpu option like below.

默认情况下,虽然列表处理将它们的PID排序。 有其他排序过程。 我们可以使用--sort=pcpu选项根据进程当前的CPU使用率对其进行排序,如下所示。

$ ps -A --sort=pcpu

根据内存使用情况对进程进行排序 (Sort Process According To Memory Usage)

We can also sort processes according to their memory usage with --sort=pmem command like below.

我们还可以使用--sort=pmem命令根据进程的内存使用情况对其进行排序,如下所示。

$ ps -aux --sort=pcpu

运行Ps实时模式 (Run Ps Real Time Mode)

The default behavior of ps command is running and exiting. ps command can be run in real-time without exiting. This is the same as top command. We will use an external command named watch and provide the ps command. In this example, we will list processes in 2-second intervals.

ps命令的默认行为是运行和退出。 ps命令可以实时运行而无需退出。 这与top命令相同。 我们将使用名为watch的外部命令并提供ps命令。 在此示例中,我们将以2秒为间隔列出进程。

$ watch -n 2 ps
Run Ps Real Time Mode
Run Ps Real Time Mode
运行Ps实时模式

翻译自: https://www.poftut.com/linux-ps-command-tutorial-list-processes-examples/

linux ps 命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值