进程管理命令
1 ps 默认显示与当前终端有关的进程信息 -e 显示系统中所有的进程信息 -f 显示更多的进程属性信息(全格式) -L 显示进程中的线程 ID
wys@DESKTOP-2OU3HRV:~/mycode$ ps -f
UID PID PPID C STIME TTY TIME CMD
wys 11 10 0 15:55 tty1 00:00:00 -bash
wys 97 11 0 19:15 tty1 00:00:00 ps -f
wys@DESKTOP-2OU3HRV:~/mycode$ ps -e
PID TTY TIME CMD
1 ? 00:00:00 init
10 tty1 00:00:00 init
11 tty1 00:00:00 bash
98 tty1 00:00:00 ps
wys@DESKTOP-2OU3HRV:~/mycode$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 11 10 0 80 0 - 4551 - tty1 00:00:00 bash
0 R 1000 99 11 0 80 0 - 4646 - tty1 00:00:00 ps
wys@DESKTOP-2OU3HRV:~/mycode$
2.pstree 以树状图形式显示进程之间的关系
wys@DESKTOP-2OU3HRV:~$ pstree
init─┬─init───bash───pstree
├─init───bash
└─{init}
wys@DESKTOP-2OU3HRV:~$
3.kill 结束或者挂起一个进程 -9 强制结束进程 -stop 挂起进程
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[1] 156
wys@DESKTOP-2OU3HRV:~$ ps -f
UID PID PPID C STIME TTY TIME CMD
wys 104 103 0 19:22 tty2 00:00:00 -bash
wys 156 104 0 19:55 tty2 00:00:00 sleep 200
wys 157 104 0 19:55 tty2 00:00:00 ps -f
wys@DESKTOP-2OU3HRV:~$ kill 156
wys@DESKTOP-2OU3HRV:~$ ps -f
UID PID PPID C STIME TTY TIME CMD
wys 104 103 0 19:22 tty2 00:00:00 -bash
wys 158 104 0 19:55 tty2 00:00:00 ps -f
[1]+ Terminated sleep 200
wys@DESKTOP-2OU3HRV:~$
4.pkill 结束一组同名的进程
wys@DESKTOP-2OU3HRV:~$ sleep 100&
[1] 160
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[2] 161
wys@DESKTOP-2OU3HRV:~$ ps -f
UID PID PPID C STIME TTY TIME CMD
wys 104 103 0 19:22 tty2 00:00:00 -bash
wys 160 104 0 19:58 tty2 00:00:00 sleep 100
wys 161 104 0 19:58 tty2 00:00:00 sleep 200
wys 162 104 0 19:58 tty2 00:00:00 ps -f
wys@DESKTOP-2OU3HRV:~$ pkill sleep
[1]- Terminated sleep 100
[2]+ Terminated sleep 200
wys@DESKTOP-2OU3HRV:~$ ps
PID TTY TIME CMD
104 tty2 00:00:00 bash
164 tty2 00:00:00 ps
wys@DESKTOP-2OU3HRV:~$
5.&后台运行程序 默认在前台执行,终端会等待前进程结束
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[1] 169
wys@DESKTOP-2OU3HRV:~$ ps
PID TTY TIME CMD
104 tty2 00:00:00 bash
169 tty2 00:00:00 sleep
170 tty2 00:00:00 ps
wys@DESKTOP-2OU3HRV:~$
6.jobs 显示当前终端的任务
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[1] 176
wys@DESKTOP-2OU3HRV:~$ sleep 300
^Z
[2]+ Stopped sleep 300
wys@DESKTOP-2OU3HRV:~$ jobs
[1]- Running sleep 200 &
[2]+ Stopped sleep 300
wys@DESKTOP-2OU3HRV:~$ jobs -l
[1]- 176 Running sleep 200 &
[2]+ 177 Stopped sleep 300
wys@DESKTOP-2OU3HRV:~$
7.fg bg fg %任务号 将后台运行的或挂起的进程挪到前台执行
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[1] 204
wys@DESKTOP-2OU3HRV:~$ fg %1
sleep 200
bg %任务号 将挂起的进程唤醒到后台执行
wys@DESKTOP-2OU3HRV:~$ sleep 200&
[1] 202
wys@DESKTOP-2OU3HRV:~$ sleep 100
^Z
[2]+ Stopped sleep 100
wys@DESKTOP-2OU3HRV:~$ jobs
[1]- Running sleep 200 &
[2]+ Stopped sleep 100
wys@DESKTOP-2OU3HRV:~$ bg %2
[2]+ sleep 100 &
wys@DESKTOP-2OU3HRV:~$ jobs
[1]- Running sleep 200 &
[2]+ Running sleep 100 &
wys@DESKTOP-2OU3HRV:~$
top 查看系统资源使用情况已经进程信息
wys@DESKTOP-2OU3HRV:~$ top
top - 20:24:08 up 4:28, 0 users, load average: 0.52, 0.58, 0.59
Tasks: 4 total, 1 running, 3 sleeping, 0 stopped, 0 zombie
%Cpu(s): 13.6 us, 6.1 sy, 0.0 ni, 79.6 id, 0.0 wa, 0.7 hi, 0.0 si, 0.0 st
MiB Mem : 8040.1 total, 3165.2 free, 4650.9 used, 224.0 buff/cache
MiB Swap: 18436.7 total, 18259.3 free, 177.4 used. 3258.6 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 8944 332 288 S 0.0 0.0 0:00.09 init
103 root 20 0 8944 232 188 S 0.0 0.0 0:00.01 init
104 wys 20 0 18204 3784 3684 S 0.0 0.0 0:00.78 bash
206 wys 20 0 18920 2136 1528 R 0.0 0.0 0:00.00 top
|