1. The basic process outlined
当我们运行一个程序,那么我们将运行的程序叫进程。
PS1: 当程序运行为进程后,系统会为该进程分配内存,以及进程运行的身份和权限。
PS2: 在进程运行的过程中,服务器上会有各种状态来表示当然进程的指标信息。
2. The difference between the programs and processes
1.程序是数据和指令的集合,是一个静态的概念。比如/bin/ls、/bin/cp等二进制文件。同时程序可以长期存在系统中。
2.进程是程序运行的过程,是一个动态的概念。进程是存在生命周期的概念的,也就是说进程会随着程序的终止而销毁,不会永久存在系统中。
3. The process life cycle
生命周期就是指一个对象的生老病死。用处很广。
4. Monitoring Process Status
使用ps命令查看当前的进程状态(静态)
状态 描述
USER 启动进程的用户
PID 进程运行的ID号
%CPU 进程占用CPU百分比
%MEM 进程占用内存百分比
VSZ 进程占用虚拟内存大小 (单位KB)
RSS 进程占用物理内存实际大小 (单位KB)
TTY 进程是由哪个终端运行启动的tty1、pts/0等 ?表示内核程序与终端无关
STAT 进程运行过程中的状态 man ps (/STATE)
START 进程的启动时间
TIME 进程占用 CPU 的总时间(为0表示还没超过秒)
COMMAND 程序的运行指令,[ 方括号 ] 属于内核态的进程。 没有 [ ] 的是用户态进程。
Detailed 5.STAT
R |
Processes running |
s |
Process control process, Ss process leader, the parent process |
S |
Interruptible sleep |
< |
Processes running on high-priority, S <a higher priority process |
T |
The process is suspended |
N |
Processes run on low priority, SN lower-priority process |
D |
Uninterruptible sleep |
+ |
The current process is running in the foreground, R + indicates that the process is running in the foreground |
WITH |
Zombie process |
l |
The process is multi-threaded, SL indicates that the process is run threads |
6.top command to view the process Detailed
任务 含义
Tasks: 80 total 当然进程的总数
1 running 正在运行的进程数
79 sleeping 睡眠的进程数
0 stopped 停止的进程数
0 zombie 僵尸进程数
%Cpu(s): 0.3 us 系统用户进程使用CPU百分比
0.3 sy 内核中的进程占用CPU百分比,通常内核是于硬件进行交互
0.0 ni 优先级的进程占用cpu的百分比
99.3 id 空闲CPU的百分比
0.0 wa CPU等待IO完成的时间
0.0 hi 硬中断,占的CPU百分比(扩展)
0.0 si 软中断,占的CPU百分比(扩展)
0.0 st 比如虚拟机占用物理主机CPU的时间
7. Detailed average load
8. real case
- Case, PS handover command to view the process status
1.在终端1上运行vim
[root@chengyinwu ~]# vim oldboy
2.在终端2上运行ps命令查看状态
[root@chengyinwu ~]# ps aux|grep oldboy S表示睡眠模式,+表示前台运行
root 29166 0.2 0.4 151256 4924 pts/0 S+ 15:19 0:00 vim oldboy
root 29173 0.0 0.1 155360 1888 pts/1 R+ 15:19 0:00 ps aux
在终端1上挂起vim命令,按下:ctrl+z
3.回到终端2再次运行ps命令查看状态
[root@chengyinwu ~]# ps aux|grep oldboy T表示停止状态
root 29166 0.0 0.4 151256 4924 pts/0 T 15:19 0:00 vim oldboy
root 29199 0.0 0.1 155360 1892 pts/1 R+ 15:20 0:00 ps aux
- Case II, PS command to view the status of the process can not be interrupted
1.使用tar打包文件时,可以通过终端不断查看状态,由S+,R+变为D+
[root@chengyinwu ~]# tar czf etc.tar.gz /etc/ /usr/ /var/
[root@chengyinwu ~]# ps aux |grep tar |grep -v grep
root 29466 3.5 0.6 128428 6260 pts/1 R+ 15:25 0:02 tar czf etc.tar.gz /etc/ /usr/ /var/
[root@chengyinwu ~]# ps aux |grep tar |grep -v grep
root 29466 3.5 0.6 128576 6276 pts/1 S+ 15:25 0:02 tar czf etc.tar.gz /etc/ /usr/ /var/
[root@chengyinwu ~]# ps aux |grep tar |grep -v grep
root 29466 3.5 0.6 128576 6276 pts/1 D+ 15:25 0:02 tar czf etc.tar.gz /etc/ /usr/ /var/