一、管理进程
1、ps命令
- 下面是man手册中的描述,注意:三种风格的参数可以混合使用,但是最好每个参数都用空格隔开,避免不必要的冲突。例如,我可以使用 ps -e l --forest来显示所有进程参数,使用UNIX风格的-e,使用BSD风格的l,以及GNU风格的–forest。
PS(1) User Commands
NAME
ps - report a snapshot of the current processes.
SYNOPSIS
ps [options]
DESCRIPTION
ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead.
This version of ps accepts several kinds of options:
1 UNIX options, which may be grouped and must be preceded by a dash.
2 BSD options, which may be grouped and must not be used with a dash.
3 GNU long options, which are preceded by two dashes.
Options of different types may be freely mixed, but conflicts can appear. There are some synonymous options, which are functionally identical, due to the many standards and ps
implementations that this ps is compatible with.
-
ps的常用命令参数举例
- -e 显示所有进程
- -a 显示除控制进程和无终端进程外的所有进程
- -L 显示进程中的线程
- -l 显示UNIX风格的长列表(CMD显示命令缩写)
- l 显示BSD风格的长列表(内容更全,command显示程序实际路径,bash貌似不是)
- -U userlist 或 -g grplist 或 -p pidlist 显示对应列表中的进程
- –forest 会通过折线图的形式展示进程的层级关系
- –info 显示调试信息
- –sort order 按指定的order输出进程信息。
-
BSD风格长列表中
- F 内核分配给进程的系统标记
- TTY 进程启动时的终端设备
- TIME 运行进程需要的累计CPU时间
- STAT 代表当前进程状态的双字状态码
- 第一个参数O代表正在运行;S代表休眠;R代表可运行,正在等待;Z代表僵化
- 第二个参数:< 该进程运行在高优先级上; N 低优先级上;L该进程有页面锁定在内存中;s控制进程;l段线程的;+运行在前台。
- VSZ 进程在内存中的大小,以KB为单位
- RSS 进程在未换出时占有的物理内存
- WCHAN 进程休眠的内核函数地址。
- 下面是使用 ps l --forest展示的内容列表:
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
0 1000 2941 2933 20 0 19320 4960 do_wai Ss pts/0 0:00 bash
4 1000 3500 2941 20 0 20120 3176 - R+ pts/0 0:00 \_ ps l --forest
4 1000 1249 1214 20 0 173872 6040 poll_s Ssl+ tty2 0:00 /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --session

本文介绍了Bash中的进程管理命令,包括使用`ps`查看进程,`top`实时监测进程以及`kill`系列命令结束进程。详细讲解了各命令的参数和用法,如`ps`的-e、-a、-L选项,`top`的系统资源显示,以及`kill`的信号传递。
最低0.47元/天 解锁文章
5764

被折叠的 条评论
为什么被折叠?



