博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux基本命令示例_Linux ps命令– 20个真实示例
阅读量:2530 次
发布时间:2019-05-11

本文共 5820 字,大约阅读时间需要 19 分钟。

linux基本命令示例

The ps command, short for Process Status, is a command line utility that is used to display or view information related to the processes running in a Linux system.

ps命令是Process Status的缩写,是一个命令行实用程序,用于显示或查看与Linux系统中运行的进程有关的信息

As we all know, Linux is a multitasking and multiprocessing system. Therefore, multiple processes can run concurrently without affecting each other.

众所周知,Linux是一个多任务和多处理系统。 因此,多个进程可以并发运行而不会互相影响。

The ps command lists current running processes alongside their PIDs and other attributes. In this guide, we are going to focus on ps command usage.

ps命令列出当前正在运行的进程及其PID和其他属性。 在本指南中,我们将重点介绍ps命令的用法。

It retrieves information about the processes from virtual files which are located in the /proc file system

它从/ proc文件系统中的虚拟文件中检索有关进程的信息

不带参数的ps命令 (ps command without arguments)

The ps command without arguments lists the running processes in the current shell

不带参数的ps命令列出了当前shell中正在运行的进程

ps

Output

输出量

The output consists of four columns

输出包括四列

PID – This is the unique process ID

PID –这是唯一的进程ID

TTY – This is the typeof terminal that the user is logged in to

TTY –这是用户登录到的终端的typeof

TIME – This is the time in minutes and seconds that the process has been running

TIME –这是进程已运行的时间,以分钟和秒为单位

CMD – The command that launched the process

CMD –启动过程的命令

以各种格式查看所有正在运行的进程 (Viewing all the running processes in different formats)

To have a glance at all the running processes, execute the command below

要浏览所有正在运行的进程,请执行以下命令

ps -A

ps -A

Output

输出量

or

要么

ps -e

ps -e

Output

输出量

查看与终端关联的进程 (View processes associated with the terminal)

To view processes associated with the terminal run

查看与终端运行关联的进程

ps -T

ps -T

Output

输出量

查看与终端不相关的进程 (View processes not associated with terminal)

To view all processes with the exception of processes associated with the terminal and session leaders

execute

查看与终端和会话负责人关联的流程以外的所有流程

执行

ps -a

ps -a

A session leader is a process that starts other processes

会话负责人是启动其他过程的过程

Output

输出量

显示所有当前正在运行的进程 (Show all current running processes)

To view all current processes execute

查看当前所有进程执行

ps -ax

Output

输出量

-a flag stands for all processes

-xwill display all processes even those not associated with the current tty

-a标志代表所有进程

-x将显示所有进程,即使那些与当前tty不相关的进程

以BSD格式显示所有进程 (Display all processes in BSD format)

If you wish to display processes in BSD format, execute

如果您希望以BSD格式显示进程,请执行

ps au

OR

要么

ps aux

Output

输出量

执行全格式列表 (To perform full format listing)

To view a full format listing run

查看完整格式的清单运行

ps -ef

OR

要么

ps -eF

Output

输出量

根据用户筛选流程 (Filter processes according to the user)

If you wish to list processes associated with a specific user, use the -u flag as shown

如果您希望列出与特定用户关联的进程,请使用-u标志,如下所示

ps -u user

For example

例如

ps -u jamie

Output

输出量

按线程筛选过程 (Filter process by thread process)

If you wish to know the thread of a particular process, make use of the -Lflag followed by the PID

如果您想了解特定进程的线程,请使用-L标志和PID

For example

例如

ps -L 4264

Output

输出量

显示以root身份运行的每个进程 (Show every process running as root)

Sometimes, you may want to reveal all processes run by the root user. To achieve this run

有时,您可能想要显示由root用户运行的所有进程。 要实现此运行

ps -U root -u root

Output

输出量

显示组流程 (Display group processes)

If you wish to list all processes associated by a certain group run

如果您希望列出某个组运行关联的所有过程

ps -fG group_name

Or

要么

ps -fG groupID

For example

例如

ps -fG root

Output

输出量

搜索过程PID (Search Process PID)

Chances are that usually don’t know the PID to a process. You can search the PID of a process by

running

通常,通常不知道进程的PID。 您可以通过以下方式搜索流程的PID

跑步

ps -C process_name

For example

例如

ps -C bash

Output

输出量

通过PID列出流程 (Listing processes by PID)

You can display processes by their PID as shown

您可以按其PID显示进程,如下所示

ps -fp PID

For example

例如

ps -fp 1294

Output

输出量

在树形图中显示流程层次结构 (To display process hierarchy in a tree diagram)

Usually, most processes are forked from parent processes. Getting to know this parent-child relationship

can come in handy. The command below searches for processes going by the name apache2

通常,大多数进程是从父进程派生的。 了解这种亲子关系

可以派上用场。 下面的命令搜索名称为apache2的进程

ps -f --forest -C bash

Output

输出量

显示父流程的子流程 (Display child processes of a parent process)

For example, If you wish to display all forked processes belonging to apache, execute

例如,如果您希望显示属于apache的所有分叉进程,请执行

ps -o pid,uname,comm -C bash

Output

输出量

The first process, which is owned by root is the main apache2 process and the rest of the processes

have been forked from this main process

由root拥有的第一个进程是主要的apache2进程,其余进程

已经从这个主要过程中分叉了

To display all the child apache2 processes using the pid of the main apache2 process execute

要使用主apache2进程的pid显示所有子apache2进程,请执行

ps --ppid PID no.

For example

例如

ps --ppid 1294

Output

输出量

显示进程线程 (Display process threads)

The ps command can be used to view threads along with the processes.

ps命令可用于查看线程以及进程。

The command below displays all the threads owned by the process with PID pid_no

下面的命令使用PID pid_no显示该进程拥有的所有线程

ps -p pid_no -L

For example

例如

ps -p 1294 -L

Output

输出量

显示选定的列列表 (Display a selected list of columns)

You can use the ps command to display only the columns you need.

您可以使用ps命令仅显示所需的列。

For example ,

例如 ,

ps -e -o pid,uname,pcpu,pmem,comm

The command above will only display the PID, Username, CPU, memory and command columns

上面的命令将仅显示PID,用户名,CPU,内存和命令列

Output

输出量

重命名列标签 (Renaming column labels)

To rename column labels execute the command below

要重命名列标签,请执行以下命令

ps -e -o pid=PID,uname=USERNAME,pcpu=CPU_USAGE,pmem=%MEM,comm=COMMAND

Output

输出量

显示进程的经过时间 (Display elapsed time of processes)

Elapsed time refers to how long the process has been running for

经过的时间是指进程已运行多长时间

ps -e -o pid,comm,etime

Output

输出量

The -o option enables the column for elapsed time

-o选项启用该列的经过时间

在grep中使用ps命令 (Using ps command with grep)

the ps command can be used with grep command to search for a particular process

ps命令可与grep命令一起使用以搜索特定进程

For example

例如

ps -ef  | grep systemd

Output

输出量

翻译自:

linux基本命令示例

转载地址:http://rlmzd.baihongyu.com/

你可能感兴趣的文章
精通ASP.NET Web程序测试
查看>>
vue 根据不同属性 设置背景
查看>>
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>
oracle之三 自动任务调度
查看>>
Android dex分包方案
查看>>
ThreadLocal为什么要用WeakReference
查看>>
删除本地文件
查看>>
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>
kibana的query string syntax 笔记
查看>>
旋转变换(一)旋转矩阵
查看>>
thinkphp3.2.3 bug集锦
查看>>
[BZOJ 4010] 菜肴制作
查看>>