目录
源码包(编译)安装
Linux操作系统启动流程详解
启动流程核心阶段
systemd管理机制
运行级别
systemctl命令的使用
Linux进程管理
进程查看命令
pstree
ps
pgrep
top、htop
以nginx为例
先下载nginx安装包网址:Release release-1.28.0 · nginx/nginx · GitHub
将安装包拖入windterm 的文件管理器
[root@localhost ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg nginx-1.28.0.tar.gz
对压缩包解压
[root@localhost ~]# tar xf nginx-1.28.0.tar.gz -C /home
[root@localhost ~]# cd /home
[root@localhost home]# ls
nginx-1.28.0 w
[root@localhost home]# cd nginx-1.28.0/
[root@localhost nginx-1.28.0]# ls
auto CHANGES.ru conf contrib html man SECURITY.md
CHANGES CODE_OF_CONDUCT.md configure CONTRIBUTING.md LICENSE README.md src
编译安装
[root@localhost nginx-1.28.0]# ./configure #我用的默认地址 如果要指定路径,使用此命令:
./configure --prefix=选择的路径
checking for OS
+ Linux 5.14.0-503.14.1.el9_5.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 11.5.0 20240719 (Red Hat 11.5.0-2) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found #太多了 跳过
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option. #发现依赖关系缺失
解决依赖关系
[root@localhost nginx-1.28.0]# yum install -y pcre-devel
Rocky Linux 9 - BaseOS 908 kB/s | 2.3 MB 00:02
Rocky Linux 9 - AppStream 2.3 MB/s | 8.4 MB 00:03
Rocky Linux 9 - Extras 8.4 kB/s | 16 kB 00:01
依赖关系解决。
===============================================================================================================
软件包 架构 版本 仓库 大小
===============================================================================================================
安装:
pcre-devel x86_64 8.44-4.el9 appstream 469 k
安装依赖关系:
pcre-cpp x86_64 8.44-4.el9 appstream 25 k
pcre-utf16 x86_64 8.44-4.el9 appstream 183 k
pcre-utf32 x86_64 8.44-4.el9 appstream 173 k
事务概要
===============================================================================================================
安装 4 软件包
总下载:850 k
安装大小:2.6 M
下载软件包:
(1/4): pcre-utf32-8.44-4.el9.x86_64.rpm 375 kB/s | 173 kB 00:00
(2/4): pcre-utf16-8.44-4.el9.x86_64.rpm 383 kB/s | 183 kB 00:00
(3/4): pcre-cpp-8.44-4.el9.x86_64.rpm 465 kB/s | 25 kB 00:00
(4/4): pcre-devel-8.44-4.el9.x86_64.rpm 862 kB/s | 469 kB 00:00
---------------------------------------------------------------------------------------------------------------
总计 428 kB/s | 850 kB 00:01
Rocky Linux 9 - AppStream 1.7 MB/s | 1.7 kB 00:00
导入 GPG 公钥 0x350D275D:
Userid: "Rocky Enterprise Software Foundation - Release key 2022 "
指纹: 21CB 256A E16F C54C 6E65 2949 702D 426D 350D 275D
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : pcre-cpp-8.44-4.el9.x86_64 1/4
安装 : pcre-utf16-8.44-4.el9.x86_64 2/4
安装 : pcre-utf32-8.44-4.el9.x86_64 3/4
安装 : pcre-devel-8.44-4.el9.x86_64 4/4
运行脚本: pcre-devel-8.44-4.el9.x86_64 4/4
验证 : pcre-utf32-8.44-4.el9.x86_64 1/4
验证 : pcre-utf16-8.44-4.el9.x86_64 2/4
验证 : pcre-devel-8.44-4.el9.x86_64 3/4
验证 : pcre-cpp-8.44-4.el9.x86_64 4/4
已安装:
pcre-cpp-8.44-4.el9.x86_64 pcre-devel-8.44-4.el9.x86_64 pcre-utf16-8.44-4.el9.x86_64
pcre-utf32-8.44-4.el9.x86_64
完毕!
继续安装
./configure
checking for OS
+ Linux 5.14.0-503.14.1.el9_5.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 11.5.0 20240719 (Red Hat 11.5.0-2) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found #太多了直接跳至结果
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
进行编译
[root@localhost nginx-1.28.0]# make
make -f objs/Makefile
make[1]: 进入目录“/home/nginx-1.28.0”
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \ #太多了 直接跳到结果
-lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/home/nginx-1.28.0”
开始安装
root@localhost nginx-1.28.0]# make install
make -f objs/Makefile install
make[1]: 进入目录“/home/nginx-1.28.0”
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
|| mv '/usr/local/nginx/sbin/nginx' \
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: 离开目录“/home/nginx-1.28.0”
安装结束 想要正常使用命令,需要创建链接至环境变量
root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
[root@localhost nginx]# nginx
查看是否启动
[root@localhost nginx]# nginx
[root@localhost nginx]# ps aux | grep nginx
root 55606 0.0 0.0 4428 1264 ? Ss 20:36 0:00 nginx: master process nginx
nobody 55607 0.0 0.1 13996 5360 ? S 20:36 0:00 nginx: worker process
root 55633 0.0 0.0 221680 2432 pts/0 S+ 20:36 0:00 grep --color=auto nginx
1.电源与固件阶段
UEFI/BIOS初始化
硬件自检
定位启动设备,读取NVRAM中的启动项(efibootmgr命令可管理)
2.引导加载程序
GRUB2 核心作用
配置文件路径: /boot/grub2/grub.cfg (由grub2-mkconfig生成)
关键的配置参数:
set root=(hd0,gpt1) # 指定/boot所在分区
linux /vmlinuz-5.4.0 root=/dev/sda2 ro # 内核路径及挂载参数
initrd /initramfs-5.4.0.img # 初始化内存文件系统
用户交互
按e临时编辑启动参数(单用户模式systemd.unit=rescue.target)
按c进入GRUB命令行
3.内核初始化
内核解压与初始化
加载vmlinuz:压缩的内核镜像
initramfs:
包含根文件系统挂载之前的驱动
提供dracut工具集 (可以通过dmesg | grep initramfs查看日志)
挂载根文件系统为只读模式
4.systemd初始化进程
首个用户态进程:
PID=1
核心任务:解析/etc/systemd/system/default.target #默认运行级别
并行启动服务单元
激活sysinit.target (系统初始化)、basic.target(基础服务)
关键操作命令:
systemctl get-default # 查看默认target
systemctl set-default multi-user.target # 设置默认为命令行模式
journalctl -b # 查看本次启动日志
5.用户登录阶段
终端登录:
getty服务生成终端
调用login验证用户身份
图形化:
Display Manager启动X/Wayland会话
init进程是所有进程的父进程,systemd实际上是一种管理init的软件。只能管理rpm安装的
units存储路径:/usr/lib/systemd/system
常见的unit类型:
Service | .service | 描述一个系统服务 |
Target | .target | 描述一组systemd的单元 |
0 | poweroff.target | 关机状态,使用该级别时将会关闭主机 |
1 | rescue.target | 单用户模式,不需要密码验证即可登录系统,多用于系统维护 |
2 | multi-user.target | 用户定义/域特定运行级别。默认等同于3 |
3 | multi-user.target | 字符界面的完整多用户模式,大多数服务器主机运行在此级别 |
4 | multi-user.target | 用户定义/域特定运行级别。默认等同于3 |
5 | graphical.target | 图形界面的多用户模式,提供了图形桌面操作环境 |
6 | reboot.target | 重新启动,使用该级别时将会重启主机 |
查看运行级别
runlevel
切换运行级别
init 运行级别数字
查看默认运行级别
systemctl get-default
设置默认运行级别
systemctl setdefault runlevel3.target 设置默认运行级别为3
start 启动
stop 停止
restart 重启
reload 重载
status 查看状态
enable 开机自启动
disable 关闭开机自启
is-enabled 查看是否开机自启
--now 配合enable与disable使用;在进行开机自启或不自启的同时进行打开或关闭指定服务
-t 指定unit类型
-A |
各进程树之间的连接以ASCII码字符来连接 |
---|---|
-p | 同时列出每个进程的PID |
pstree
[root@localhost ~]# pstree
systemd─┬─ModemManager───3*[{ModemManager}]
├─NetworkManager───2*[{NetworkManager}]
├─VGAuthService
├─accounts-daemon───3*[{accounts-daemon}]
├─alsactl
├─anacron
├─at-spi-bus-laun─┬─dbus-daemon
│ └─3*[{at-spi-bus-laun}]
├─at-spi2-registr───2*[{at-spi2-registr}]
├─atd
├─auditd─┬─sedispatch
│ └─2*[{auditd}]
├─avahi-daemon───avahi-daemon
├─bluetoothd
├─chronyd
├─colord───3*[{colord}]
├─crond
├─cupsd
├─dbus-broker-lau───dbus-broker
├─firewalld───{firewalld}
├─gdm─┬─gdm-session-wor─┬─gdm-wayland-ses─┬─dbus-run-sessio─┬─dbus-daemon
│ │ │ │ └─gnome-session-b─┬─gnome-shell─┬─Xwayland
│ │ │ │ │ ├─ibus-dae+
│ │ │ │ │ └─6*[{gnom+
│ │ │ │ ├─gsd-a11y-settin───3*[{+
│ │ │ │ ├─gsd-color───3*[{gsd-co+
│ │ │ │ ├─gsd-datetime───3*[{gsd+
│ │ │ │ ├─gsd-housekeepin───3*[{+
│ │ │ │ ├─gsd-keyboard───3*[{gsd+
│ │ │ │ ├─gsd-media-keys───3*[{g+
│ │ │ │ ├─gsd-power───3*[{gsd-po+
│ │ │ │ ├─gsd-print-notif───2*[{+
│ │ │ │ ├─gsd-rfkill───2*[{gsd-r+
│ │ │ │ ├─gsd-screensaver───2*[{+
│ │ │ │ ├─gsd-sharing───3*[{gsd-+
│ │ │ │ ├─gsd-smartcard───5*[{gs+
│ │ │ │ ├─gsd-sound───3*[{gsd-so+
│ │ │ │ ├─gsd-wacom───3*[{gsd-wa+
│ │ │ │ └─3*[{gnome-session-b}]
│ │ │ └─2*[{gdm-wayland-ses}]
│ │ └─2*[{gdm-session-wor}]
│ └─2*[{gdm}]
├─2*[gjs───4*[{gjs}]]
├─gsd-printer───2*[{gsd-printer}]
├─ibus-portal───2*[{ibus-portal}]
├─ibus-x11───2*[{ibus-x11}]
├─irqbalance───{irqbalance}
├─lsmd
├─nginx───nginx
├─polkitd───5*[{polkitd}]
├─power-profiles-───2*[{power-profiles-}]
├─rsyslogd───2*[{rsyslogd}]
├─rtkit-daemon───2*[{rtkit-daemon}]
├─sshd───sshd───sshd─┬─bash───pstree
│ └─sftp-server
├─switcheroo-cont───2*[{switcheroo-cont}]
├─systemd───(sd-pam)
├─systemd─┬─(sd-pam)
│ ├─dbus-broker-lau───dbus-broker
│ ├─pipewire───2*[{pipewire}]
│ ├─pipewire-pulse───2*[{pipewire-pulse}]
│ └─wireplumber───4*[{wireplumber}]
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─udisksd───4*[{udisksd}]
├─upowerd───2*[{upowerd}]
├─vmtoolsd───2*[{vmtoolsd}]
├─vmware-vmblock-───2*[{vmware-vmblock-}]
├─wpa_supplicant
└─xdg-permission-───2*[{xdg-permission-}]
pstree -A
[root@localhost ~]# pstree -A
systemd-+-ModemManager---3*[{ModemManager}]
|-NetworkManager---2*[{NetworkManager}]
|-VGAuthService
|-accounts-daemon---3*[{accounts-daemon}]
|-alsactl
|-anacron
|-at-spi-bus-laun-+-dbus-daemon
| `-3*[{at-spi-bus-laun}]
|-at-spi2-registr---2*[{at-spi2-registr}]
|-atd
|-auditd-+-sedispatch
| `-2*[{auditd}]
|-avahi-daemon---avahi-daemon
|-bluetoothd
|-chronyd
|-colord---3*[{colord}]
|-crond
|-cupsd
|-dbus-broker-lau---dbus-broker
|-firewalld---{firewalld}
|-gdm-+-gdm-session-wor-+-gdm-wayland-ses-+-dbus-run-sessio-+-dbus-daemon
| | | | `-gnome-session-b-+-gnome-shell-+-Xwayland
| | | | | |-ibus-dae+
| | | | | `-6*[{gnom+
| | | | |-gsd-a11y-settin---3*[{+
| | | | |-gsd-color---3*[{gsd-co+
| | | | |-gsd-datetime---3*[{gsd+
| | | | |-gsd-housekeepin---3*[{+
| | | | |-gsd-keyboard---3*[{gsd+
| | | | |-gsd-media-keys---3*[{g+
| | | | |-gsd-power---3*[{gsd-po+
| | | | |-gsd-print-notif---2*[{+
| | | | |-gsd-rfkill---2*[{gsd-r+
| | | | |-gsd-screensaver---2*[{+
| | | | |-gsd-sharing---3*[{gsd-+
| | | | |-gsd-smartcard---5*[{gs+
| | | | |-gsd-sound---3*[{gsd-so+
| | | | |-gsd-wacom---3*[{gsd-wa+
| | | | `-3*[{gnome-session-b}]
| | | `-2*[{gdm-wayland-ses}]
| | `-2*[{gdm-session-wor}]
| `-2*[{gdm}]
|-2*[gjs---4*[{gjs}]]
|-gsd-printer---2*[{gsd-printer}]
|-ibus-portal---2*[{ibus-portal}]
|-ibus-x11---2*[{ibus-x11}]
|-irqbalance---{irqbalance}
|-lsmd
|-nginx---nginx
|-polkitd---5*[{polkitd}]
|-power-profiles----2*[{power-profiles-}]
|-rsyslogd---2*[{rsyslogd}]
|-rtkit-daemon---2*[{rtkit-daemon}]
|-sshd---sshd---sshd-+-bash---pstree
| `-sftp-server
|-switcheroo-cont---2*[{switcheroo-cont}]
|-systemd---(sd-pam)
|-systemd-+-(sd-pam)
| |-dbus-broker-lau---dbus-broker
| |-pipewire---2*[{pipewire}]
| |-pipewire-pulse---2*[{pipewire-pulse}]
| `-wireplumber---4*[{wireplumber}]
|-systemd-journal
|-systemd-logind
|-systemd-udevd
|-udisksd---4*[{udisksd}]
|-upowerd---2*[{upowerd}]
|-vmtoolsd---2*[{vmtoolsd}]
|-vmware-vmblock----2*[{vmware-vmblock-}]
|-wpa_supplicant
`-xdg-permission----2*[{xdg-permission-}]
pstree -p
[root@localhost ~]# pstree -p
systemd(1)─┬─ModemManager(943)─┬─{ModemManager}(954)
│ ├─{ModemManager}(957)
│ └─{ModemManager}(960)
├─NetworkManager(1048)─┬─{NetworkManager}(1052)
│ └─{NetworkManager}(1053)
├─VGAuthService(902)
├─accounts-daemon(883)─┬─{accounts-daemon}(890)
│ ├─{accounts-daemon}(891)
│ └─{accounts-daemon}(893)
├─alsactl(928)
├─anacron(51000)
├─at-spi-bus-laun(1491)─┬─dbus-daemon(1496)
│ ├─{at-spi-bus-laun}(1492)
│ ├─{at-spi-bus-laun}(1493)
│ └─{at-spi-bus-laun}(1495)
├─at-spi2-registr(1728)─┬─{at-spi2-registr}(1731)
│ └─{at-spi2-registr}(1732)
├─atd(1084)
├─auditd(843)─┬─sedispatch(845)
│ ├─{auditd}(844)
│ └─{auditd}(846)
├─avahi-daemon(873)───avahi-daemon(918)
├─bluetoothd(874)
├─chronyd(896)
├─colord(1924)─┬─{colord}(1933)
│ ├─{colord}(1934)
│ └─{colord}(1936)
├─crond(1087)
├─cupsd(1073)
├─dbus-broker-lau(871)───dbus-broker(872)
├─firewalld(945)───{firewalld}(1166)
├─gdm(1089)─┬─gdm-session-wor(1111)─┬─gdm-wayland-ses(1163)─┬─dbus-run-sessio(1169)─┬─dbus-daemon(1+
│ │ │ │ └─gnome-session+
│ │ │ ├─{gdm-wayland-ses}(1164)
│ │ │ └─{gdm-wayland-ses}(1168)
│ │ ├─{gdm-session-wor}(1112)
│ │ └─{gdm-session-wor}(1114)
│ ├─{gdm}(1095)
│ └─{gdm}(1097)
├─gjs(1726)─┬─{gjs}(1733)
│ ├─{gjs}(1734)
│ ├─{gjs}(1746)
│ └─{gjs}(1747)
├─gjs(1961)─┬─{gjs}(1969)
│ ├─{gjs}(1970)
│ ├─{gjs}(1972)
│ └─{gjs}(1973)
├─gsd-printer(1852)─┬─{gsd-printer}(1873)
│ └─{gsd-printer}(1876)
├─ibus-portal(1983)─┬─{ibus-portal}(1985)
│ └─{ibus-portal}(1997)
├─ibus-x11(1980)─┬─{ibus-x11}(2012)
│ └─{ibus-x11}(2013)
├─irqbalance(877)───{irqbalance}(889)
├─lsmd(878)
├─nginx(55606)───nginx(55607)
├─polkitd(880)─┬─{polkitd}(924)
│ ├─{polkitd}(925)
│ ├─{polkitd}(926)
│ ├─{polkitd}(927)
│ └─{polkitd}(937)
├─power-profiles-(881)─┬─{power-profiles-}(897)
│ └─{power-profiles-}(899)
├─rsyslogd(1177)─┬─{rsyslogd}(1211)
│ └─{rsyslogd}(1212)
├─rtkit-daemon(882)─┬─{rtkit-daemon}(885)
│ └─{rtkit-daemon}(886)
├─sshd(1074)───sshd(2014)───sshd(2035)─┬─bash(2036)───pstree(58813)
│ └─sftp-server(2122)
├─switcheroo-cont(887)─┬─{switcheroo-cont}(907)
│ └─{switcheroo-cont}(911)
├─systemd(2019)───(sd-pam)(2021)
├─systemd(1123)─┬─(sd-pam)(1128)
│ ├─dbus-broker-lau(1165)───dbus-broker(1167)
│ ├─pipewire(1667)─┬─{pipewire}(1672)
│ │ └─{pipewire}(1683)
│ ├─pipewire-pulse(1670)─┬─{pipewire-pulse}(1675)
│ │ └─{pipewire-pulse}(1684)
│ └─wireplumber(1669)─┬─{wireplumber}(1674)
│ ├─{wireplumber}(1680)
│ ├─{wireplumber}(1681)
│ └─{wireplumber}(1698)
├─systemd-journal(728)
├─systemd-logind(888)
├─systemd-udevd(747)
├─udisksd(894)─┬─{udisksd}(909)
│ ├─{udisksd}(912)
│ ├─{udisksd}(950)
│ └─{udisksd}(1031)
├─upowerd(900)─┬─{upowerd}(914)
│ └─{upowerd}(915)
├─vmtoolsd(903)─┬─{vmtoolsd}(933)
│ └─{vmtoolsd}(934)
├─vmware-vmblock-(748)─┬─{vmware-vmblock-}(749)
│ └─{vmware-vmblock-}(750)
├─wpa_supplicant(1708)
└─xdg-permission-(1607)─┬─{xdg-permission-}(1614)
└─{xdg-permission-}(1619)
显示系统当前进程瞬间运行状态
[root@localhost ~]# ps
PID TTY TIME CMD
2036 pts/0 00:00:00 bash
58979 pts/0 00:00:00 ps
-A | 所有的进程均显示出来,与 -e 具有同样的效用 |
---|---|
-a | 显示现行终端机下的所有进程,包括其他用户的进程 |
-u | 以用户为主的进程状态 |
-x | 通常与 a 这个参数一起使用,可列出较完整信息 |
ps -A
[root@localhost ~]# ps -A
PID TTY TIME CMD
1 ? 00:00:01 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 pool_workqueue_
4 ? 00:00:00 kworker/R-rcu_g
5 ? 00:00:00 kworker/R-rcu_p
6 ? 00:00:00 kworker/R-slub_
7 ? 00:00:00 kworker/R-netns
10 ? 00:00:00 kworker/u512:0-events_unbound
11 ? 00:00:00 kworker/R-mm_pe
12 ? 00:00:00 kworker/u512:1-netns
13 ? 00:00:00 rcu_tasks_kthre
14 ? 00:00:00 rcu_tasks_rude_
15 ? 00:00:00 rcu_tasks_trace
16 ? 00:00:00 ksoftirqd/0
17 ? 00:00:00 rcu_preempt
18 ? 00:00:00 migration/0
19 ? 00:00:00 idle_inject/0
21 ? 00:00:00 cpuhp/0
22 ? 00:00:00 cpuhp/1
23 ? 00:00:00 idle_inject/1 #太多了
ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 108424 16532 ? Ss 19:16 0:01 /usr/lib/systemd/systemd rhgb --switched-roo
root 2 0.0 0.0 0 0 ? S 19:16 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 19:16 0:00 [pool_workqueue_]
root 4 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-rcu_g]
root 5 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-rcu_p]
root 6 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-slub_]
root 7 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-netns]
root 10 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u512:0-events_unbound]
root 11 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-mm_pe]
root 12 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u512:1-netns]
root 13 0.0 0.0 0 0 ? I 19:16 0:00 [rcu_tasks_kthre]
root 14 0.0 0.0 0 0 ? I 19:16 0:00 [rcu_tasks_rude_]
root 15 0.0 0.0 0 0 ? I 19:16 0:00 [rcu_tasks_trace]
root 16 0.0 0.0 0 0 ? S 19:16 0:00 [ksoftirqd/0]
root 17 0.0 0.0 0 0 ? I 19:16 0:00 [rcu_preempt]
root 18 0.0 0.0 0 0 ? S 19:16 0:00 [migration/0]
root 19 0.0 0.0 0 0 ? S 19:16 0:00 [idle_inject/0]
root 21 0.0 0.0 0 0 ? S 19:16 0:00 [cpuhp/0]
root 22 0.0 0.0 0 0 ? S 19:16 0:00 [cpuhp/1]
root 23 0.0 0.0 0 0 ? S 19:16 0:00 [idle_inject/1]
root 24 0.0 0.0 0 0 ? S 19:16 0:00 [migration/1]
root 25 0.0 0.0 0 0 ? S 19:16 0:00 [ksoftirqd/1]
root 27 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/1:0H-events_highpri]
root 28 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u513:0-events_unbound]
root 32 0.0 0.0 0 0 ? S 19:16 0:00 [kdevtmpfs]
root 33 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-inet_]
root 34 0.0 0.0 0 0 ? S 19:16 0:00 [kauditd]
root 37 0.0 0.0 0 0 ? S 19:16 0:00 [khungtaskd]
root 38 0.0 0.0 0 0 ? S 19:16 0:00 [oom_reaper]
root 40 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-write]
root 41 0.0 0.0 0 0 ? S 19:16 0:00 [kcompactd0]
root 42 0.0 0.0 0 0 ? SN 19:16 0:00 [ksmd]
root 44 0.0 0.0 0 0 ? SN 19:16 0:00 [khugepaged]
root 45 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-crypt]
root 46 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kinte]
root 47 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kbloc]
root 48 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-blkcg]
root 50 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-tpm_d]
root 51 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-md]
root 52 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-md_bi]
root 53 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-edac-]
root 54 0.0 0.0 0 0 ? S 19:16 0:00 [watchdogd]
root 55 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/1:1H-kblockd]
root 56 0.0 0.0 0 0 ? S 19:16 0:00 [kswapd0]
root 62 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kthro]
root 67 0.0 0.0 0 0 ? S 19:16 0:00 [irq/24-pciehp]
root 68 0.0 0.0 0 0 ? S 19:16 0:00 [irq/25-pciehp]
root 69 0.0 0.0 0 0 ? S 19:16 0:00 [irq/26-pciehp]
root 70 0.0 0.0 0 0 ? S 19:16 0:00 [irq/27-pciehp]
root 71 0.0 0.0 0 0 ? S 19:16 0:00 [irq/28-pciehp]
root 72 0.0 0.0 0 0 ? S 19:16 0:00 [irq/29-pciehp]
root 73 0.0 0.0 0 0 ? S 19:16 0:00 [irq/30-pciehp]
root 74 0.0 0.0 0 0 ? S 19:16 0:00 [irq/31-pciehp]
root 75 0.0 0.0 0 0 ? S 19:16 0:00 [irq/32-pciehp]
root 76 0.0 0.0 0 0 ? S 19:16 0:00 [irq/33-pciehp]
root 77 0.0 0.0 0 0 ? S 19:16 0:00 [irq/34-pciehp]
root 78 0.0 0.0 0 0 ? S 19:16 0:00 [irq/35-pciehp]
root 79 0.0 0.0 0 0 ? S 19:16 0:00 [irq/36-pciehp]
root 80 0.0 0.0 0 0 ? S 19:16 0:00 [irq/37-pciehp]
root 81 0.0 0.0 0 0 ? S 19:16 0:00 [irq/38-pciehp]
root 82 0.0 0.0 0 0 ? S 19:16 0:00 [irq/39-pciehp]
root 83 0.0 0.0 0 0 ? S 19:16 0:00 [irq/40-pciehp]
root 84 0.0 0.0 0 0 ? S 19:16 0:00 [irq/41-pciehp]
root 85 0.0 0.0 0 0 ? S 19:16 0:00 [irq/42-pciehp]
root 86 0.0 0.0 0 0 ? S 19:16 0:00 [irq/43-pciehp]
root 87 0.0 0.0 0 0 ? S 19:16 0:00 [irq/44-pciehp]
root 88 0.0 0.0 0 0 ? S 19:16 0:00 [irq/45-pciehp]
root 89 0.0 0.0 0 0 ? S 19:16 0:00 [irq/46-pciehp]
root 90 0.0 0.0 0 0 ? S 19:16 0:00 [irq/47-pciehp]
root 91 0.0 0.0 0 0 ? S 19:16 0:00 [irq/48-pciehp]
root 92 0.0 0.0 0 0 ? S 19:16 0:00 [irq/49-pciehp]
root 93 0.0 0.0 0 0 ? S 19:16 0:00 [irq/50-pciehp]
root 94 0.0 0.0 0 0 ? S 19:16 0:00 [irq/51-pciehp]
root 95 0.0 0.0 0 0 ? S 19:16 0:00 [irq/52-pciehp]
root 96 0.0 0.0 0 0 ? S 19:16 0:00 [irq/53-pciehp]
root 97 0.0 0.0 0 0 ? S 19:16 0:00 [irq/54-pciehp]
root 98 0.0 0.0 0 0 ? S 19:16 0:00 [irq/55-pciehp]
root 99 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-acpi_]
root 100 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kmpat]
root 101 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kalua]
root 102 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-mld]
root 103 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/0:1H-kblockd]
root 104 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-ipv6_]
root 114 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kstrp]
root 228 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/u515:0-hci0]
root 229 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/u516:0-ttm]
root 230 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/u517:0-ttm]
root 436 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-nvme-]
root 439 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-nvme-]
root 441 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-nvme-]
root 442 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-nvme-]
root 447 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-ata_s]
root 451 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_0]
root 452 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 453 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_1]
root 455 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 469 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_2]
root 470 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 472 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_3]
root 474 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 476 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_4]
root 477 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 478 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_5]
root 479 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 480 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_6]
root 481 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 482 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_7]
root 483 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 484 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_8]
root 485 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 486 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_9]
root 487 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 489 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_10]
root 491 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 493 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_11]
root 496 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 498 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_12]
root 499 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 500 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_13]
root 501 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 502 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_14]
root 504 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 505 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_15]
root 506 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 507 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_16]
root 508 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 509 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_17]
root 510 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 511 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_18]
root 512 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 513 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_19]
root 514 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 515 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_20]
root 516 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 517 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_21]
root 518 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 519 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_22]
root 520 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 521 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_23]
root 522 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 523 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_24]
root 524 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 525 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_25]
root 526 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 527 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_26]
root 528 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 529 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_27]
root 530 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 531 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_28]
root 532 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 533 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_29]
root 534 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 535 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_30]
root 536 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 537 0.0 0.0 0 0 ? S 19:16 0:00 [scsi_eh_31]
root 538 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-scsi_]
root 563 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u514:27-events_unbound]
root 564 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u514:28-events_unbound]
root 566 0.0 0.0 0 0 ? I 19:16 0:00 [kworker/u514:29-events_unbound]
root 571 0.0 0.0 0 0 ? S 19:16 0:00 [irq/16-vmwgfx]
root 572 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-ttm]
root 584 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/0:2H-kblockd]
root 622 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kdmfl]
root 629 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-kdmfl]
root 647 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfsal]
root 648 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs_m]
root 649 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-b]
root 650 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-c]
root 651 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-r]
root 652 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-b]
root 653 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-i]
root 654 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-l]
root 655 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-c]
root 656 0.0 0.0 0 0 ? S 19:16 0:00 [xfsaild/dm-0]
root 728 0.0 0.2 28068 10496 ? Ss 19:16 0:00 /usr/lib/systemd/systemd-journald
root 747 0.0 0.3 39516 14816 ? Ss 19:16 0:00 /usr/lib/systemd/systemd-udevd
root 748 0.0 0.1 152424 5256 ? Ssl 19:16 0:00 vmware-vmblock-fuse /run/vmblock-fuse -o rw,
root 804 0.0 0.0 0 0 ? S 19:16 0:00 [irq/76-vmw_vmci]
root 805 0.0 0.0 0 0 ? S 19:16 0:00 [irq/77-vmw_vmci]
root 806 0.0 0.0 0 0 ? S 19:16 0:00 [irq/78-vmw_vmci]
root 826 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/u515:2-hci0]
root 830 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-b]
root 831 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-c]
root 832 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-r]
root 833 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-b]
root 834 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-i]
root 835 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-l]
root 836 0.0 0.0 0 0 ? I< 19:16 0:00 [kworker/R-xfs-c]
root 837 0.0 0.0 0 0 ? S 19:16 0:00 [xfsaild/nvme0n1]
root 843 0.0 0.1 92760 4764 ? S
进程状态:
S:休眠
s:父进程
R:运行
Z:僵尸进程(前台程序已死,但后台驻留进程没有正常退出;后果就是占用资源不干活。)
查看进程的信息,包括进程是否已经消亡,通过pgrep来获得正在被调度的进程的相关信息。 pgrep通过匹配其程序名,找到匹配的进程
pgrep -l 同时显示进程名和PID
[root@localhost ~]# pgrep -l nginx
55606 nginx
55607 nginx
top:动态监控系统处理器状态,htop姑且称之为top的增强版
htop需要下载
yum install epel-release -y #安装epel源
yum install htop -y #安装htop
-d
:指定更新的间隔时间,以秒为单位。
-n
:指定更新的次数。
-p
:监控指定进程的 ID。
-u
:监控指定用户的进程。
top -d 5`:每隔 5 秒更新一次进程信息。
`top -n 2`:更新两次进程信息后退出。
`top -p 1234`:监控进程 ID 为 1234 的进程。
`top -u root`:监控 root 用户的进程。
空格:立即刷新
M: 按内存使用的百分比排序
P:按cpu 的使用百分比排序
T: 按进程运行时间排序
q: 退出
h: 帮助信息