目录
一、进程查看命令
1、pstree
用于查看进程树之间的关系,谁是父进程,谁是子进程,可以清楚的看出来是谁创建了谁
例:
[root@bogon ~]# pstree
systemd─┬─ModemManager───3*[{ModemManager}]
├─NetworkManager───2*[{NetworkManager}]
├─VGAuthService
├─accounts-daemon───3*[{accounts-daemon}]
├─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-daemon─┬─ibus-d+
│ │ │ │ │ │ ├─ibus-e+
│ │ │ │ │ │ └─2*[{ib+
│ │ │ │ │ └─8*[{gnome-shell}]
│ │ │ │ ├─gsd-a11y-settin───3*[{gsd-a11y-set+
│ │ │ │ ├─gsd-color───3*[{gsd-color}]
│ │ │ │ ├─gsd-datetime───3*[{gsd-datetime}]
│ │ │ │ ├─gsd-housekeepin───3*[{gsd-housekee+
│ │ │ │ ├─gsd-keyboard───3*[{gsd-keyboard}]
│ │ │ │ ├─gsd-media-keys───3*[{gsd-media-key+
│ │ │ │ ├─gsd-power───3*[{gsd-power}]
│ │ │ │ ├─gsd-print-notif───2*[{gsd-print-no+
│ │ │ │ ├─gsd-rfkill───2*[{gsd-rfkill}]
│ │ │ │ ├─gsd-screensaver───2*[{gsd-screensa+
│ │ │ │ ├─gsd-sharing───3*[{gsd-sharing}]
│ │ │ │ ├─gsd-smartcard───5*[{gsd-smartcard}+
│ │ │ │ ├─gsd-sound───3*[{gsd-sound}]
│ │ │ │ ├─gsd-wacom───3*[{gsd-wacom}]
│ │ │ │ └─3*[{gnome-session-b}]
│ │ │ └─2*[{gdm-wayland-ses}]
│ │ └─2*[{gdm-session-wor}]
│ └─2*[{gdm}]
├─2*[gjs───6*[{gjs}]]
├─gsd-printer───2*[{gsd-printer}]
├─ibus-portal───2*[{ibus-portal}]
├─ibus-x11───2*[{ibus-x11}]
├─irqbalance───{irqbalance}
├─lsmd
├─mcelog
├─polkitd───7*[{polkitd}]
├─power-profiles-───2*[{power-profiles-}]
├─rsyslogd───2*[{rsyslogd}]
├─rtkit-daemon───2*[{rtkit-daemon}]
├─sshd───sshd───sshd─┬─bash─┬─bash───pk-command-not-───3*[{pk-command-not-}]
│ │ └─pstree
│ └─sftp-server
├─switcheroo-cont───2*[{switcheroo-cont}]
├─systemd─┬─(sd-pam)
│ ├─dbus-broker-lau───dbus-broker
│ ├─pipewire───{pipewire}
│ └─wireplumber───3*[{wireplumber}]
├─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-}]
选项
-A 详细查看各进程树
[root@bogon ~]# pstree -a
systemd rhgb --switched-root --system --deserialize 31
├─ModemManager
│ └─3*[{ModemManager}]
├─NetworkManager --no-daemon
│ └─2*[{NetworkManager}]
├─VGAuthService -s
├─accounts-daemon
│ └─3*[{accounts-daemon}]
├─at-spi-bus-laun
│ ├─dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
│ └─3*[{at-spi-bus-laun}]
├─at-spi2-registr --use-gnome-session
│ └─2*[{at-spi2-registr}]
├─atd -f
├─auditd
│ ├─sedispatch
│ └─2*[{auditd}]
├─avahi-daemon
│ └─avahi-daemon
├─bluetoothd
├─chronyd -F 2
├─colord
│ └─3*[{colord}]
├─crond -n
├─cupsd -l
├─dbus-broker-lau --scope system --audit
│ └─dbus-broker --log 4 --controller 9 --machine-id d525975a6f3e40fbaf5ae56434453fa9 --max-bytes 536870912 ...
├─firewalld -s /usr/sbin/firewalld --nofork --nopid
│ └─{firewalld}
├─gdm
│ ├─gdm-session-wor
│ │ ├─gdm-wayland-ses --register-sessiondbus-run-session -- gnome-session --autostart /usr/share/gdm/greeter/au
│ │ │ ├─dbus-run-sessio -- gnome-session --autostart /usr/share/gdm/greeter/autostart
│ │ │ │ ├─dbus-daemon --nofork --print-address 4 --session
│ │ │ │ └─gnome-session-b --autostart /usr/share/gdm/greeter/autostart
│ │ │ │ ├─gnome-shell
│ │ │ │ │ ├─Xwayland :1024 -rootless -noreset -accessx -core -auth ...
│ │ │ │ │ ├─ibus-daemon --panel disable -r --xim
│ │ │ │ │ │ ├─ibus-dconf
│ │ │ │ │ │ │ └─3*[{ibus-dconf}]
│ │ │ │ │ │ ├─ibus-engine-sim
│ │ │ │ │ │ │ └─2*[{ibus-engine-sim}]
│ │ │ │ │ │ └─2*[{ibus-daemon}]
│ │ │ │ │ └─8*[{gnome-shell}]
│ │ │ │ ├─gsd-a11y-settin
│ │ │ │ │ └─3*[{gsd-a11y-settin}]
│ │ │ │ ├─gsd-color
│ │ │ │ │ └─3*[{gsd-color}]
│ │ │ │ ├─gsd-datetime
│ │ │ │ │ └─3*[{gsd-datetime}]
│ │ │ │ ├─gsd-housekeepin
│ │ │ │ │ └─3*[{gsd-housekeepin}]
│ │ │ │ ├─gsd-keyboard
│ │ │ │ │ └─3*[{gsd-keyboard}]
│ │ │ │ ├─gsd-media-keys
│ │ │ │ │ └─3*[{gsd-media-keys}]
│ │ │ │ ├─gsd-power
│ │ │ │ │ └─3*[{gsd-power}]
│ │ │ │ ├─gsd-print-notif
│ │ │ │ │ └─2*[{gsd-print-notif}]
│ │ │ │ ├─gsd-rfkill
│ │ │ │ │ └─2*[{gsd-rfkill}]
│ │ │ │ ├─gsd-screensaver
│ │ │ │ │ └─2*[{gsd-screensaver}]
│ │ │ │ ├─gsd-sharing
│ │ │ │ │ └─3*[{gsd-sharing}]
│ │ │ │ ├─gsd-smartcard
│ │ │ │ │ └─5*[{gsd-smartcard}]
│ │ │ │ ├─gsd-sound
│ │ │ │ │ └─3*[{gsd-sound}]
│ │ │ │ ├─gsd-wacom
│ │ │ │ │ └─3*[{gsd-wacom}]
│ │ │ │ └─3*[{gnome-session-b}]
│ │ │ └─2*[{gdm-wayland-ses}]
│ │ └─2*[{gdm-session-wor}]
│ └─2*[{gdm}]
├─gjs /usr/share/gnome-shell/org.gnome.Shell.Notifications
│ └─6*[{gjs}]
├─gjs /usr/share/gnome-shell/org.gnome.ScreenSaver
│ └─6*[{gjs}]
├─gsd-printer
│ └─2*[{gsd-printer}]
├─ibus-portal
│ └─2*[{ibus-portal}]
├─ibus-x11 --kill-daemon
│ └─2*[{ibus-x11}]
├─irqbalance
│ └─{irqbalance}
├─lsmd -d
├─mcelog --daemon --foreground
├─polkitd --no-debug
│ └─7*[{polkitd}]
├─power-profiles-
│ └─2*[{power-profiles-}]
├─rsyslogd -n
│ └─2*[{rsyslogd}]
├─rtkit-daemon
│ └─2*[{rtkit-daemon}]
├─sshd
│ └─sshd
│ └─sshd
│ ├─bash
│ │ ├─bash
│ │ │ └─pk-command-not- yun install httpd
│ │ │ └─3*[{pk-command-not-}]
│ │ └─pstree -a
│ └─sftp-server
├─switcheroo-cont
│ └─2*[{switcheroo-cont}]
├─systemd --user
│ ├─(sd-pam)
│ ├─dbus-broker-lau --scope user
│ │ └─dbus-broker --log 4 --controller 9 --machine-id d525975a6f3e40fbaf5ae56434453fa9 --max-bytes ...
│ ├─pipewire
│ │ └─{pipewire}
│ └─wireplumber
│ └─3*[{wireplumber}]
├─systemd --user
│ ├─(sd-pam)
│ ├─dbus-broker-lau --scope user
│ │ └─dbus-broker --log 4 --controller 9 --machine-id d525975a6f3e40fbaf5ae56434453fa9 --max-bytes ...
│ ├─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- /run/vmblock-fuse -o rw,subtype=vmware-vmblock,default_permissions,allow_other,dev,suid
│ └─2*[{vmware-vmblock-}]
├─wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -s
└─xdg-permission-
└─2*[{xdg-permission-}]
2、ps
显示系统当前进程瞬间运行状态
用法:
ps [选项]
选项:
-A | 所有的进程均显示出来,与 -e 具有同样的效用 |
---|---|
-a | 显示现行终端机下的所有进程,包括其他用户的进程 |
-u | 以用户为主的进程状态 |
-x | 通常与 a 这个参数一起使用,可列出较完整信息 |
-l | 较长、较详细的将该PID 的的信息列出 |
常用命令
aux 查看系统所有运行的进程状态的
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 183680 18236 ? Ss 12:03 0:25 /usr/lib/systemd/systemd rhgb --switched-root --system --deserialize 31
root 2 0.0 0.0 0 0 ? S 12:03 0:00 [kthreadd]
elf 显示进程的详细信息
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
4 0 45822 45821 20 0 224636 5888 do_wai Ss pts/1 0:01 -bash USER=root LOGNAME=root HOME=/root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin SHELL=/bin/bash TERM=xterm-256color SELINUX_ROLE_REQUESTED= SELINUX_LEVEL_REQUESTED= SELINUX_USE_CURRENT_RANGE= MOTD_SHOWN=pam XDG_SESSION_ID=4 XDG_RUNTIME_DIR=/run/user/0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus XDG_SESSION_TYPE=tty XDG_SESSION_CLASS=user SSH_CLIENT=192.168.157.1 53720 22 SSH_CONNECTION=192.168.157.1 53720 192.168.157.135 22 SSH_TTY=/dev/pts/1
输出解析:**
-
USER
:进程的所有者。 -
PID
:进程的 ID。 -
%CPU
:进程占用的 CPU 百分比。 -
%MEM
:进程占用的内存百分比。 -
VSZ
:进程使用的虚拟内存大小。 -
RSS
:进程使用的物理内存大小。 -
TTY
:进程所在的终端。 -
STAT
:进程的状态,如S
(休眠)、R
(运行)、Z
(僵尸进程)等。 -
START
:进程的启动时间。 -
TIME
:进程运行的时间。 -
COMMAND
:启动进程的命令。
进程状态:
S:休眠
s:父进程
R:运行
Z:僵尸进程(前台程序已死,但后台驻留进程没有正常退出;后果就是占用资源不干活。)
3、pgrep
查看进程的信息,包括进程是否已经消亡,通过pgrep来获得正在被调度的进程的相关信息。 pgrep通过匹配其程序名,找到匹配的进程
用法:
pgrep [选项] pidname
选项:
-l | 同时显示进程名和PID |
---|---|
-o | 当匹配多个同一命令启动的进程时,显示进程号最小的那个 |
-n | 当匹配多个同意命令启动的进程时,显示进程号最大的那个 |
例:
[root@bogon ~]# pgrep -l httpd
96823 httpd
96908 httpd
96909 httpd
96910 httpd
96911 httpd
4、top、htop
这两个是动态监控系统处理器状态,htop更全面,需要注意的是,用htop往往需要先下载源
yum install epel-release -y #安装epel源
yum install htop -y #安装htop
例
top
[root@bogon ~]# top
top - 20:08:10 up 8:04, 3 users, load average: 0.33, 0.40, 0.27 #当前时间值 启动时间 登录用户数量 平均负载: 一分钟 五分钟 十分钟(十分钟的最需要注意)
Tasks: 315 total, 1 running, 312 sleeping, 2 stopped, 0 zombie #目前进程数 运行数 休眠数 停止的 僵尸的
%Cpu(s): 1.5 us, 1.5 sy, 0.0 ni, 96.6 id, 0.0 wa, 0.3 hi, 0.1 si, #cpu占用比 用户的 系统的 优先级 优先级补偿值 空闲cpu使用率 硬中断 软中断
MiB Mem : 3626.1 total, 914.9 free, 1112.4 used, 1908.1 buff/cache #物理内存 buff/cahe:缓存和缓冲
MiB Swap: 4012.0 total, 4012.0 free, 0.0 used. 2513.6 avail Mem #交换内存 总数 以使用的 和可用的
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+
96909 apache 20 0 2358840 21500 5632 S 0.7 0.6 0:00.73
99008 root 20 0 226032 4224 3328 R 0.7 0.1 0:00.87
681 root 20 0 0 0 0 S 0.3 0.0 0:08.18
899 root 16 -4 92760 4252 1536 S 0.3 0.1 0:02.51
973 root 20 0 457744 9216 7680 S 0.3 0.2 1:49.39
45821 root 20 0 20588 7100 5120 S 0.3 0.2 0:20.36
84355 gdm 20 0 3962732 202556 115396 S 0.3 5.5 0:12.68
91512 root 20 0 0 0 0 I 0.3 0.0 0:00.57
97992 root 20 0 0 0 0 I 0.3 0.0 0:01.22
1 root 20 0 183680 18236 10864 S 0.0 0.5 0:24.75
2 root 20 0 0 0 0 S 0.0 0.0 0:00.58
3 root 20 0 0 0 0 S 0.0 0.0 0:00.00
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00
htop (看起来像图片一样,是动态的)
0[|||||| 9.8%] Tasks: 94, 317 thr, 221 kthr; 0 running
1[|| 2.3%] Load average: 0.09 0.04 0.09
2[|| 1.1%] Uptime: 08:26:30
3[|||||||| 13.4%]
Mem[||||||||||||||||||||||||||||||||||||||||||| 790M/3.54G]
Swp[|| 252K/3.92G]
[Main] [I/O]
PID USER PRI NI VIRT RES SHR S CPU%▽MEM% TIME+ Command
102406 root 20 0 219M 5248 3968 R 4.6 0.1 0:01.57 htop
973 root 20 0 447M 9216 7680 S 0.0 0.2 1:52.11 /usr/bin/vmtoolsd
1 root 20 0 179M 18236 10864 S 0.0 0.5 0:25.98 /usr/lib/systemd/systemd rhgb --switched-root --system -
752 root 20 0 44592 11776 10240 S 0.0 0.3 0:02.18 /usr/lib/systemd/systemd-journald
769 root 20 0 148M 2956 768 S 0.0 0.1 0:00.06 vmware-vmblock-fuse /run/vmblock-fuse -o rw,subtype=vmwa
770 root 20 0 148M 2956 768 S 0.0 0.1 0:00.01 vmware-vmblock-fuse /run/vmblock-fuse -o rw,subtype=vmwa
771 root 20 0 148M 2956 768 S 0.0 0.1 0:00.00 vmware-vmblock-fuse /run/vmblock-fuse -o rw,subtype=vmwa
777 root 20 0 38328 13280 8960 S 0.0 0.4 0:01.44 /usr/lib/systemd/systemd-udevd
899 root 16 -4 92760 4252 1536 S 0.0 0.1 0:01.83 /sbin/auditd
900 root 16 -4 92760 4252 1536 S 0.0 0.1 0:00.05 /sbin/auditd
901 root 16 -4 7816 3200 2944 S 0.0 0.1 0:00.59 /usr/sbin/sedispatch
902 root 16 -4 92760 4252 1536 S 0.0 0.1 0:00.77 /sbin/auditd
928 dbus 20 0 10984 4812 3968 S 0.0 0.1 0:00.24 /usr/bin/dbus-broker-launch --scope system --audit
929 dbus 20 0 7952 5424 2304 S 0.0 0.1 0:03.28 dbus-broker --log 4 --controller 9 --machine-id d525975a
930 avahi 20 0 16856 6528 5760 S 0.0 0.2 0:00.29 avahi-daemon: running [linux.local]
934 root 20 0 82896 4352 3968 S 0.0 0.1 0:02.92 /usr/sbin/irqbalance
F1Help F2Setup F3SearchF4FilterF5Tree F6SortByF7Nice -F8Nice +F9Kill F10Quit
常用按键:
-
空格键:立即刷新显示。
-
M:按照内存使用百分比对进程进行排序。
-
P:按照 CPU 使用百分比对进程进行排序。
-
T:按照进程运行时间对进程进行排序。
-
q:退出 top 命令。
-
h:显示帮助信息。
二、进程管理命令
1、kill
语法:
kill [选项] pid
终止进程
例:
[root@bogon ~]# ps -aux | grep httpd
root 96823 0.0 0.3 21236 11412 ? Ss 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96908 0.0 0.1 22968 7268 ? S 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96909 0.0 0.5 2358840 21500 ? Sl 13:32 0:02 /usr/sbin/httpd -DFOREGROUND
apache 96910 0.0 0.4 2162168 15112 ? Sl 13:32 0:01 /usr/sbin/httpd -DFOREGROUND
apache 96911 0.0 0.4 2162168 15152 ? Sl 13:32 0:01 /usr/sbin/httpd -DFOREGROUND
root 104787 0.0 0.0 221680 2304 pts/0 S+ 14:29 0:00 grep --color=auto httpd
[root@bogon ~]# kill 96909
[root@bogon ~]# ps -aux | grep httpd
root 96823 0.0 0.3 21236 11412 ? Ss 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96908 0.0 0.1 22968 7268 ? S 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96909 0.0 0.5 2358840 21500 ? Sl 13:32 0:02 /usr/sbin/httpd -DFOREGROUND
apache 96910 0.0 0.4 2162168 15112 ? Sl 13:32 0:01 /usr/sbin/httpd -DFOREGROUND
apache 96911 0.0 0.4 2162168 15152 ? Sl 13:32 0:01 /usr/sbin/httpd -DFOREGROUND
root 105211 0.0 0.0 221680 2304 pts/0 S+ 14:32 0:00 grep --color=auto httpd
杀死失败,因为父进程给它“复活”了
**选项:
-9 强制终结一个进程
[root@bogon ~]# kill -9 96909
[root@bogon ~]# ps -aux | grep httpd
root 96823 0.0 0.3 21236 11412 ? Ss 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96908 0.0 0.1 22968 7268 ? S 13:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 96910 0.0 0.4 2162168 15112 ? Sl 13:32 0:02 /usr/sbin/httpd -DFOREGROUND
apache 96911 0.0 0.4 2162168 15152 ? Sl 13:32 0:01 /usr/sbin/httpd -DFOREGROUND
apache 105657 1.4 0.4 2227580 15056 ? Sl 14:36 0:00 /usr/sbin/httpd -DFOREGROUND
root 105738 0.0 0.0 221680 2304 pts/0 S+ 14:36 0:00 grep --color=auto httpd
确实没96909进程了,不过多了105657进程,因为这个文件配置的要求必须有四个进程,就算终结了也会有新的替换上来
当然也能这么用
[root@bogon ~]# pgrep httpd
135082
135168
135169
135170
135171
[root@bogon ~]# kill -9 `pgrep httpd`
[root@bogon ~]# pgrep httpd
停止查看进程的进程
2、pkill与killall
pkill是ps命令和kill命令的结合,按照进程名来杀死指定进程,pkill和killall应用方法差不多,也是直接杀死运行中的程序,如果想杀掉单个进程,请用kill来杀掉。
用法:
pkill/killall [选项] 进程名
例:
killall
[root@bogon nginx]# ps aux | grep nginx
root 114910 0.0 0.2 448492 8196 pts/0 Tl 15:21 0:00 /usr/libexec/pk-command-not-found ststemctl statu nginx
root 131418 0.0 0.0 11236 1596 ? Ss 16:22 0:00 nginx: master process /usr/sbin/nginx
nginx 131419 0.0 0.1 15560 4924 ? S 16:22 0:00 nginx: worker process
nginx 131420 0.0 0.1 15560 4924 ? S 16:22 0:00 nginx: worker process
nginx 131421 0.1 0.1 15560 5052 ? S 16:22 0:00 nginx: worker process
nginx 131422 0.1 0.1 15560 4924 ? S 16:22 0:00 nginx: worker process
root 131468 0.0 0.0 221680 2304 pts/0 S+ 16:23 0:00 grep --color=auto nginx
[root@bogon nginx]# killall nginx #删除进程
[root@bogon nginx]# !ps
ps aux | grep nginx
root 114910 0.0 0.2 448492 8196 pts/0 Tl 15:21 0:00 /usr/libexec/pk-command-not-found ststemctl statu nginx
root 133485 0.0 0.0 221680 2304 pts/0 S+ 16:39 0:00 grep --color=auto nginx
pkill
[root@bogon nginx]# ps aux | grep httpd
root 134055 0.2 0.3 21236 11256 ? Ss 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 134121 0.0 0.1 22968 7144 ? S 16:43 0:00 /usr/sbin/httpd -DFOREGROUND
apache 134122 0.1 0.4 2424376 17520 ? Sl 16:43 0:00 /usr/sbin/httpd -DFOREGROUND
apache 134123 0.0 0.4 2227704 15156 ? Sl 16:43 0:00 /usr/sbin/httpd -DFOREGROUND
apache 134124 0.1 0.4 2227704 15148 ? Sl 16:43 0:00 /usr/sbin/httpd -DFOREGROUND
root 134482 0.0 0.0 221680 2304 pts/0 S+ 16:44 0:00 grep --color=auto httpd
[root@bogon nginx]# pkill -9 httpd #强制删除进程
[root@bogon nginx]# ps aux | grep httpd
root 134751 0.0 0.0 221680 2304 pts/0 S+ 16:46 0:00 grep --color=auto httpd
三、进程类型
1、前台进程
在终端界面运行的进程,运行前台进程后,终端无法操作可用jobs查看
例:
首先开启前台进程
[root@bogon ~]# systemctl stop nginx
[root@bogon ~]# nginx -g "daemon off;"#让nginx在前台运行的指令
额,这里出现问题了,因为nginx比较特殊,用jobs无法查看前端进程,给大家展示下jobs查看前端进程的页面吧
root@bogon ~]# jobs
[1]+ 已停止 ststemctl statu nginx (工作目录: /usr/local)
其它方式:
#将前台进程放到后台运行
firefox &
#注意:该运行前台进程的方式,当终端关闭时,进程也会随着关闭
nohup firefox & #关闭终端,进程不掉
#查看
jobs
#将进程调到前台运行
fg 1
#将正在运行的前台进程放到后台运行
ctrl + z
bg 1
例: