本文共 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文件系统中的虚拟文件中检索有关进程的信息
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
–启动过程的命令
To have a glance at all the running processes, execute the command below
要浏览所有正在运行的进程,请执行以下命令
ps -A
ps -A
Output
输出量
or
要么
ps -e
ps -e
Output
输出量
To view processes associated with the terminal run
查看与终端运行关联的进程
ps -T
ps -T
Output
输出量
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
输出量
To view all current processes execute
查看当前所有进程执行
ps -ax
Output
输出量
-a
flag stands for all processes
-x
will display all processes even those not associated with the current tty -a
标志代表所有进程
-x
将显示所有进程,即使那些与当前tty不相关的进程 If you wish to display processes in BSD format, execute
如果您希望以BSD格式显示进程,请执行
ps au
OR
要么
ps aux
Output
输出量
To view a full format listing run
查看完整格式的清单运行
ps -ef
OR
要么
ps -eF
Output
输出量
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
输出量
If you wish to know the thread of a particular process, make use of the -L
flag followed by the PID
如果您想了解特定进程的线程,请使用-L
标志和PID
For example
例如
ps -L 4264
Output
输出量
Sometimes, you may want to reveal all processes run by the root user. To achieve this run
有时,您可能想要显示由root用户运行的所有进程。 要实现此运行
ps -U root -u root
Output
输出量
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
输出量
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
输出量
You can display processes by their PID as shown
您可以按其PID显示进程,如下所示
ps -fp PID
For example
例如
ps -fp 1294
Output
输出量
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
输出量
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
输出量
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
输出量
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
输出量
To rename column labels execute the command below
要重命名列标签,请执行以下命令
ps -e -o pid=PID,uname=USERNAME,pcpu=CPU_USAGE,pmem=%MEM,comm=COMMAND
Output
输出量
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选项启用该列的经过时间
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/