1、ps命令,该命令可以查看哪些进程正在运行及其运行状态;
2、Top命令,该命令可以实时显示各个线程情况;
3、Pstree命令,该命令以树状图的方式展现进程之间的派生关系;
4、Pgrep命令等等。
Linux ps (英文全拼:process status)命令用于显示当前进程的状态,类似于 windows 的任务管理器。语法代码语言:javascript代码运行次数:0运行复制<code class="javascript">ps [options][--help]</code>
参数:
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义-A 列出所有的进程![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121846589.jpg)
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121877969.jpg)
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121868653.jpg)
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121925905.jpg)
<code class="javascript">ps -ef | grep 进程关键字</code>
例如显示 emqx 的进程:
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121996506.jpg)
<code class="javascript"># ps -ef | grep php</code>
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121935729.jpg)
显示进程信息:ps
显示指定用户信息
代码语言:javascript代码运行次数:0运行复制<code class="javascript"># ps -u root //显示root进程用户信息</code>
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323121946377.jpg)
显示所有进程信息,连同命令行
代码语言:javascript代码运行次数:0运行复制<code class="javascript"># ps -ef //显示所有命令,连带命令行</code>
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323122097943.jpg)
2.Top命令top命令可以实时显示各个线程情况。要在top输出中开启线程查看,请调用top命令的“-H”选项,该选项会列出所有Linux线程。在top运行时,你也可以通过按“H”键将线程查看模式切换为开或关。
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323122070216.jpg)
3.Pstree命令pstree命令以树状图的方式展现进程之间的派生关系,显示效果比较直观。Pstree命令语法:pstree(选项)-a显示完整命令及参数-c重复进程分别显示-c显示进程ID、PID -n按PID排列进程PSTR
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323122040995.jpg)
4. Pgrep命令pgrep命令以名称为依据从运行进程队列中查找进程,并显示查找到的进程id。每一个进程ID以一个十进制数表示,通过一个分割字符串和下一个ID分开,默认的分割字符串是一个新行。对于每个属性选项,用户可以在命令行上指定一个以逗号分割的可能值的集合。Pgrep命令语法:
pgrep [options]
pgrep(选项)(参数)
代码语言:javascript代码运行次数:0运行复制<code class="javascript">-d, --delimiter <string> specify output delimiter -l, --list-name list PID and process name -a, --list-full list PID and full command line -v, --inverse negates the matching -w, --lightweight list all TID -c, --count count of matching processes -f, --full use full process name to match -g, --pgroup <PGID,...> match listed process group IDs -G, --group <GID,...> match real group IDs -n, --newest select most recently started -o, --oldest select least recently started -P, --parent <PPID,...> match only child processes of the given parent -s, --session <SID,...> match session IDs -t, --terminal <tty,...> match by controlling terminal -u, --euid <ID,...> match by effective IDs -U, --uid <ID,...> match by real IDs -x, --exact match exactly with the command name -F, --pidfile <file> read PIDs from file -L, --logpidfile fail if PID file is not locked --ns <PID> match the processes that belong to the samenamespace as <pid> --nslist <ns,...> list which namespaces will be considered for the --ns option. Available namespaces: ipc, mnt, net, pid, user, uts -h, --help display this help and exit -V, --version output version information and exit</code>
-l显示进程名和进程PID -o进程起始ID -n进程终止ID
![[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)](https://img.php.cn/upload/article/001/503/042/175323122032397.jpg)
以上就是[Linux] 学习笔记1-查看进程的命令(ps/top/pstree/pgrep)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号