zoukankan      html  css  js  c++  java
  • 第二十九章 进程管理

    一、进程的概述

    1.什么是进程?

    当我们运行一个程序,那么我们就将该程序称为进程。

    注意:

    当程序运行为进程后,系统会为该进程分配内存,以及运行的身份和权限。

    分配了系统的资源   文件描述符  进程描述符  网络端口   ID号  PID   PPID   

    系统会记录进程的运行中的状态   STATAE

    在进程运行的过程中,服务器上会有各种状态来表示当前进程的指标信息。

    2.进程和程序的区别

    程序是指令和数据的有序集合  静态的概念    永久存在的

    进程是程序在主机上面运行的一个过程  动态的概念  会随着程序的创建,运行,终止,消除而终止  临时的

    3.进程的生命周期

      每一个进程都有其生命周期,例如创建、运行、终止和消除。这些阶段会在系统启动和运行中重复无数次。因此,进程的生命周期对于其性能的分析是非常重要的。

    进程的运行过程:

      用户运行了一个程序,系统会给进程分配任务,进程会通过fork一个子进程,子进程会继承父进程的衣钵,子进程处理具体的任务,父进程就会进入等待状态,子进程任务结束,回来向父进程交任务,子进程正常退出;

      子进程在执行任务时,父进程因为意外原因退出了,那么子进程就会变成无人管理,就是僵尸进程

      每个进程都有自己的代号  ID号  子进程  PID  父进程  PPID

    二、进程的状态

    1.使用ps命令查看当前的进程状态

    ps aux 是常用组合,查看进程用户、PID、占用cpu百分比占用内存百分比、状态、执行的命令等。

    ps    #显示所有进程

      a    #显示所有进程

      u    #显示有效的1用户或者UID

      x    #显示没有终端

      aux  

      -e    #显示所有进程

      -f     #显示用户的ppid

      -ef     #显示所有的进程及进程的ppid

     每一列表示的含义:

    USER      #进程运行的身份  用户

    PID       #进程的ID号

    PPID       #父进程的ID号

    %CPU       #进程占用CPU的百分比

    %MEM      #进程占用内存的百分比

    VSZ        #虚拟内存集  进程占用虚拟内存的大小

    RSS         #物理内存集  进程占用物理内存的大小

    TTY       #终端    

        ?     #没有终端 内核运行的程序

        tty1      #机器的终端 服务器的本地

        pts/0   #虚拟远程终端

    STAT         #进程的状态

        S      #休眠的状态

        R      #正在运行的状态

        D     #无法中断的休眠状态

        T      #暂停或被追踪的状态

        Z      #僵尸状态

        s     #父进程

        <     #优先级高

        N      #优先级低

        l       #多线程

        +      #在前台运行

    START       #进程的启动时间

    TIME        #进程占用CPU的时间

    COMMAND     #执行的指令或者命令

      []        #内核运行的

      无[]       #用户运行的

     

    案例1

    [root@jindada ~]# vim test.log

    #另外一个窗口

    [root@jindada ~]# ps aux |grep -v grep | grep vim
    root 12592 0.2 0.2 149168 4996 pts/0 S+ 09:04 0:00 vim test.log
    [root@jindada ~]# ps aux | grep [v]im
    root 12592 0.1 0.2 149168 4996 pts/0 S+ 09:04 0:00 vim test.log


    [root@jindada ~]# vim test.log #ctrl + z 放入到后台

    [1]+ Stopped vim test.log

     

    [root@jindada ~]# ps aux | grep [v]im
    root 12592 0.0 0.2 149168 4996 pts/0 T 09:04 0:00 vim test.log


    案例二

    [root@jindada ~]# tar czf etc.tar.gz /usr /etc/ /var
    tar: Removing leading `/' from member names
    tar: Removing leading `/' from hard link targets

     

    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 7.0 0.0 123408 1352 pts/0 R+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 6.0 0.0 123408 1352 pts/0 D+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 6.2 0.0 123540 1352 pts/0 R+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 5.8 0.0 123540 1352 pts/0 D+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 5.5 0.0 123540 1352 pts/0 D+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 6.5 0.0 123540 1352 pts/0 S+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 5.8 0.0 123540 1352 pts/0 S+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var
    [root@jindada ~]# ps aux | grep [t]ar
    root 12617 6.1 0.0 123540 1352 pts/0 R+ 09:08 0:00 tar czf etc.tar.gz /usr /etc/ /var


    [root@jindada ~]# ps aux | grep [b]ash
    root 7193 0.0 5.4 225028 111152 pts/0 Ss Aug03 0:04 -bash
    root 12575 0.0 0.1 115572 2120 pts/1 Ss+ 09:04 0:00 -bash
    root 12641 0.0 5.4 225028 110280 pts/0 R+ 09:09 0:00 -bash


    案例三

    [root@jindada ~]# vim test.c
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <errno.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>


    int main(int argc, char *argv[])
    {
    pid_t pid;
    pid = fork();
    if (pid == 0) {
    int iPid = (int)getpid();
    fprintf(stderr,"I am child,%d ",iPid);
    sleep(1);
    fprintf(stderr, "Child exits ");
    return EXIT_SUCCESS;
    }
    int iPid = (int)getpid();
    fprintf(stderr,"I am parent,%d ",iPid);
    fprintf(stderr, "sleep.... ");
    sleep(600);
    fprintf(stderr, "parent exits ");
    return EXIT_SUCCESS;
    }


    [root@jindada ~]# gcc test.c
    [root@jindada ~]# ll
    total 1218672
    -rwxr-xr-x 1 root root 8696 Aug 4 09:11 a.out
    -rw-r--r-- 1 root root 199327744 Aug 4 09:09 etc.tar.gz
    -rw------- 1 root root 1048576000 Aug 3 11:22 swap.txt
    -rw-r--r-- 1 root root 547 Aug 4 09:10 test.c
    [root@jindada ~]# ./a.out
    I am parent,12655
    sleep....
    I am child,12656
    Child exits
    ^C

     

    [root@jindada ~]# ps aux | grep [a.]out
    root 12655 0.0 0.0 4208 352 pts/0 S+ 09:11 0:00 ./a.out
    root 12656 0.0 0.0 0 0 pts/0 Z+ 09:11 0:00 [a.out] <defunct>

    2.使用top命令查看当前的进程状态(动态)

    top    htop    #动态显示进程状态

    [root@jindada ~]# yum install -y htop

    [root@jindada ~]# top
    top - 09:33:58 up 23:31, 2 users, load average: 0.24, 0.10, 0.07
    Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie
    %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
    KiB Mem : 2028088 total, 155648 free, 363844 used, 1508596 buff/cache
    KiB Swap: 2097148 total, 2069756 free, 27392 used. 974036 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

     

    top - 09:33:58 up 23:31, 2 users, load average: 0.24, 0.10, 0.07


    09:33:58   #当前系统时间

    up 23:31   #系统运行时间

    2 users    #登录用户的数量 连接终端的数量

    load average: 0.24, 0.10, 0.07 #系统平均负载时间 1 5 15 分钟的平均负载


    Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie

    任务:

    113 total,   #总共有113个任务

    1 running    #一个在运行状态

    112 sleeping   #112休眠状态 S

    0 stopped    #0个停止状态

    0 zombie   #0个在僵尸状态


    %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

    系统各个状态所占用CPU的时间百分比

    0.0 us    #用户态 用户所占用的CPU的时间百分比

    0.0 sy    #系统态 系统所占用的CPU的时间百分比

    0.0 ni    #使用优先级的程序所占用的CPU的时间百分比

    100.0 id   #空闲状态所占用的CPU的时间百分比

    0.0 wa    #IO等待所占用的CPU的时间百分比

    0.0 hi    #硬中断所占用的CPU的时间百分比

    0.0 si    #软中断所占用的CPU的时间百分比

    0.0 st    #宿主机的监控程序所窃取的虚拟机的CPU的时间百分比


    KiB Mem : 2028088 total, 155648 free, 363844 used, 1508596 buff/cache


    物理内存 总的 剩余的 已使用的 缓存和缓冲中的内存

     

    KiB Swap: 2097148 total, 2069756 free, 27392 used. 974036 avail Mem

    虚拟内存


    PID   #进程的ID号


    USER    #运行的身份 用户

    PR   #优先级 20

    NI    #nice值 跟PR 相差 20个数 值越低,优先级就越高

    VIRT    #所占用的虚拟内存的大小

    RES    #所占用的物理内存的大小

    SHR   #共享内存

    S   #进程的状态

    %CPU    #占用CPU的百分比

    %MEM   #占用内存的百分比

    TIME+    #CPU的运行时间

    COMMAND    #运行的指令或者命令


    top命令的内部指令

    h    #查看帮出

    z    #高亮显示

    1   #显示所有CPU的负载

    s   #设置刷新时间

    b    #高亮显示处于R状态的进程

    M    #按内存使用百分比排序输出

    P   #按CPU使用百分比排序输出

    R    #对排序进行反转

    f   #自定义显示字段

    k   #kill掉指定PID进程

    W   #保存top环境设置 ~/.toprc

    q    #退出


    top选项:

    [root@jindada ~]# top -d 1   #设置刷新时间


    [root@jindada ~]# top -d 1 -p 1   #查看某个进程ID的进程状态


    [root@jindada ~]# top -d 1 -u postfix   #显示指定运行用户的进程状态


    [root@jindada ~]# free -m
    total used free shared buff/cache available
    Mem: 1980 265 907 12 807 1114
    Swap: 2047 29 2018


    [root@jindada ~]# yum install -y glances


    [root@jindada ~]# glances

    三、终止进程

    1.使用kill -l 列出当前系统所支持的信号


    kill      #管理系统中的信号输出

    [root@jindada ~]# kill -l
    1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
    6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
    11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
    16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
    21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
    26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
    31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
    38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
    43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
    48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
    53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
    58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
    63) SIGRTMAX-1 64) SIGRTMAX


    1     #重新加载配置 进程pid的不变


    2     #终止信号 ctrl + c


    9      #终止进程 强制终止


    15      #默认信号 终止进程 可加可不加


    18      #让暂停的进程继续运行


    20     #ctrl + z 将进程暂停


    [root@jindada ~]# yum install -y nginx

    [root@jindada ~]# systemctl start nginx
    [root@jindada ~]# ps aux | grep nginx
    root 13063 0.0 0.1 120796 2096 ? Ss 10:36 0:00 nginx: master process /usr/sbin/nginx
    nginx 13064 0.2 0.1 121180 3128 ? S 10:36 0:00 nginx: worker process


    [root@jindada ~]# kill -1 13063
    [root@jindada ~]# ps aux | grep nginx
    root 13063 0.0 0.2 121452 5248 ? Ss 10:36 0:00 nginx: master process /usr/sbin/nginx
    nginx 13070 0.0 0.1 121876 3836 ? S 10:37 0:00 nginx: worker process

     

    [root@jindada ~]# netstat -lntp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13063/nginx: master

    [root@jindada ~]# kill -1 13063
    [root@jindada ~]# netstat -lntp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 13063/nginx: master


    [root@jindada ~]# top

    [root@jindada ~]# ps aux |grep [t]op
    root 13115 0.0 0.1 161988 2212 pts/1 S+ 10:41 0:00 top
    [root@jindada ~]# kill -2 13115
    [root@jindada ~]# ps aux |grep [t]op
    [root@jindada ~]#


    [root@jindada ~]# kill -9 13063

     

    [root@jindada ~]# kill 13141
    [root@jindada ~]# ps aux |grep [t]op
    root 13144 0.0 0.1 161984 2212 pts/1 S+ 10:44 0:00 top
    [root@jindada ~]# kill -15 13144

     

    kill      #根据进程ID去终止进程的 进程不存在时,会进行提示


    #根据名称终止进程 精确匹配


    [root@jindada ~]# killall top

    [root@jindada ~]# killall nginx


    [root@jindada ~]# killall nginx     #进程不存在时,会提示
    nginx: no process found


    [root@jindada ~]# ps aux | grep [v]im
    root 13264 0.0 0.2 149168 4972 pts/0 S+ 10:53 0:00 vim 123.txt
    root 13265 0.1 0.2 149168 4972 pts/1 S+ 10:53 0:00 vim 123.log
    [root@jindada ~]# killall vim

     

    pkill      #根据进程名称终止 终止进程不会提示 模糊杀手


    [root@jindada ~]# ps aux | grep [t]op
    root 13278 0.0 0.1 161988 2216 pts/0 S+ 10:56 0:00 top
    root 13279 0.1 0.1 122396 2112 pts/1 S+ 10:56 0:00 htop
    [root@jindada ~]# pkill top
    [root@jindada ~]# ps aux | grep [t]op
    [root@jindada ~]#

    [root@jindada ~]# ps aux |grep sh
    root 6935 0.0 0.0 112756 1276 ? Ss Aug03 0:00 /usr/sbin/sshd -D
    root 7191 0.0 0.0 161364 1616 ? Ss Aug03 0:00 sshd: root@pts/0
    root 7193 0.0 5.4 225028 111168 pts/0 Ss+ Aug03 0:05 -bash
    root 12573 0.0 0.2 161364 5936 ? Ss 09:04 0:00 sshd: root@pts/1
    root 12575 0.0 0.1 115572 2196 pts/1 Ss 09:04 0:00 -bash
    root 13215 0.0 0.2 161364 6056 ? Ss 10:50 0:00 sshd: root@pts/2
    root 13217 0.0 0.1 115572 2184 pts/2 Ss 10:50 0:00 -bash
    root 13296 0.0 0.0 113176 1196 pts/2 S+ 10:59 0:00 sh 123.txt
    root 13299 0.0 0.0 113176 1216 ? Ss 10:59 0:00 /bin/sh -c /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
    root 13302 0.0 0.0 112708 976 pts/1 R+ 10:59 0:00 grep --color=auto sh
    [root@jindada ~]# pkill sh


    #以树形结构显示进程状态

    [root@jindada ~]# pstree
    systemd─┬─NetworkManager───2*[{NetworkManager}]
    ├─VGAuthService
    ├─auditd───{auditd}
    ├─crond───crond───sh───ntpdate
    ├─dbus-daemon
    ├─firewalld───{firewalld}
    ├─login───bash
    ├─master─┬─pickup
    │ └─qmgr
    ├─ping
    ├─polkitd───6*[{polkitd}]
    ├─rsyslogd───2*[{rsyslogd}]
    ├─sshd───sshd───bash───pstree
    ├─systemd-journal
    ├─systemd-logind
    ├─systemd-udevd
    ├─tuned───4*[{tuned}]
    ├─vmtoolsd
    └─vsftpd

     

    四、管理进程的后台

    1. 什么是后台进程

    通常进程都会在终端前台运行,但是一旦关闭终端,进程也会随着结束,那么此时我们就希望进程能在后台运行,就是将在前台运行的进程放到后台运行,这样即使我们关闭了终端也不影响进程的正常运行。

    2. 为什么要把进程放到后台运行

    企业中很多时候会有一些需求:

    比如:我们此前在国内服务器往国外服务器传输大文件时,由于网络问题需要传输很久,如果在传输的过程中出现网络抖动或者不小心关闭了终端则会导致传输失败,如果能将传输的进程放入后台,是不是就能解决此类问题了。

    3. 使用什么工具可以把进程放到后台

    早期的时候,大家都选择使用&符号将进程放到后台运行,然后再使用jobs、bg、fg等方式查看进程状态,但太麻烦了,也不直观,所以我们推荐使用screen。

    1)jobs、bg、fg的使用(不推荐,了解即可)

    [root@jindada ~]# sleep 3000 & #运行程序(时),让其在后台执行

    [root@jindada ~]# sleep 4000 #^Z,将前台的程序挂起(暂停)到后台

    [2]+ Stopped sleep 4000
    [root@jindada ~]# ps aux |grep sleep
    [root@jindada ~]# jobs #查看后台作业
    [1]- Running sleep 3000 &
    [2]+ Stopped sleep 4000


    [root@jindada ~]# bg %2   #让作业 2 在后台运行
    [root@jindada ~]# fg %1    #将作业 1 调回到前台
    [root@jindada ~]# kill %1 #  kill 1,终止 PID 为 1 的进程


    #进程在后台运行,但输出依然在当前终端


    [root@jindada ~]# (while :; do date; sleep 2; done) &


    [root@jindada ~]# (while :; do date; sleep 2; done) &>/dev/null &

    2)screen的使用(强烈推荐,生产必用)


    使用screen时会开启一个子bash窗口,关闭父bash并不影响子bash。


    #1.安装
    [root@jindada ~]# yum install screen -y


    #2.开启一个screen窗口,指定名称
    [root@jindada ~]# screen -S wget_mysql


    #3.在screen窗口中执行任务即可。


    #4.平滑的退出screen,但不会终止screen中的任务。注意: 如果使用exit才算真的关闭screen窗口
    ctrl+a+d


    #5.查看当前正在运行的screen有哪些
    [root@jindada ~]# screen -list
    There is a screen on:
    22058.wget_mysql (Detached)
    1 Socket in /var/run/screen/S-root.


    #6.进入正在运行的screen
    [root@jindada ~]# screen -r wget_mysql
    [root@jindada ~]# screen -r 22058

    [root@jindada ~]# tar czf etc.tar.gz /usr/ /etc/ /var
    tar: Removing leading `/' from member names
    tar: Removing leading `/' from hard link targets


    Connection closed.

    Disconnected from remote host(虚拟机-10.0.0.100) at 11:13:33.

    Type `help' to learn how to use Xshell prompt.
    [C:~]$

    Connecting to 10.0.0.100:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.

    Last login: Tue Aug 4 11:12:44 2020 from 10.0.0.1
    [root@jindada ~]# ll
    total 35408
    -rw-r--r-- 1 root root 36257792 Aug 4 11:13 etc.tar.gz
    [root@jindada ~]# ll -h
    total 35M
    -rw-r--r-- 1 root root 35M Aug 4 11:13 etc.tar.gz
    [root@jindada ~]# tar czf etc.tar.gz /usr/ /etc/ /var
    tar: Removing leading `/' from member names
    tar: Removing leading `/' from hard link targets
    ^C
    [root@jindada ~]# ll -h
    total 128M
    -rw-r--r-- 1 root root 104M Aug 4 11:14 etc.tar.gz
    [root@jindada ~]#

     

    #将程序放入到后台运行

    1. nohup &

    [root@jindada ~]# nohup ping www.baidu.com &
    [1] 13517
    [root@jindada ~]# nohup: ignoring input and appending output to ‘nohup.out’

    [root@jindada ~]#


    [root@jindada ~]# nohup ping www.baidu.com &
    [1] 13592
    [root@jindada ~]# nohup: ignoring input and appending output to ‘nohup.out’

    [root@jindada ~]#
    [root@jindada ~]#
    [root@jindada ~]# ps aux |grep 13592
    root 13592 0.0 0.0 149968 1988 pts/1 S 11:17 0:00 ping www.baidu.com
    root 13594 0.0 0.0 112708 976 pts/1 R+ 11:17 0:00 grep --color=auto 13592


    [root@jindada ~]# jobs #显示当前窗口的后台进程
    [1]+ Running nohup ping www.baidu.com &


    [root@jindada ~]# vim test.log

    [2]+ Stopped vim test.log
    [root@jindada ~]# jobs
    [1]- Running nohup ping www.baidu.com &
    [2]+ Stopped vim test.log

    #将后台程序放入到前台运行

    [root@jindada ~]# fg %2


    #将暂停在后台的程序继续在后台运行 输出还是输出到屏幕上面

    [root@jindada ~]# bg %2
    [2]+ ping www.baidu.com &


    [root@jindada ~]# ping www.baidu.com
    PING www.a.shifen.com (112.80.248.75) 56(84) bytes of data.
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=1 ttl=128 time=16.5 ms
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=2 ttl=128 time=13.7 ms
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=3 ttl=128 time=13.8 ms
    ^Z
    [1]+ Stopped ping www.baidu.com
    [root@jindada ~]# jobs
    [1]+ Stopped ping www.baidu.com
    [root@jindada ~]# fg %1
    ping www.baidu.com
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=4 ttl=128 time=14.2 ms
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=5 ttl=128 time=14.5 ms
    64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=6 ttl=128 time=14.7 ms
    ^C
    --- www.a.shifen.com ping statistics ---
    7 packets transmitted, 6 received, 14% packet loss, time 48609ms
    rtt min/avg/max/mdev = 13.700/14.604/16.559/0.955 ms


    2. screen #后台管理程序


    #列出screen后台运行的程序

    [root@jindada ~]# screen -list
    No Sockets found in /var/run/screen/S-root.

    [root@jindada ~]#

    [root@jindada ~]# screen -S vim #打开一个新的窗口 并指定窗口名称
    [detached from 13659.vim]

    [root@jindada ~]# screen -list
    There is a screen on:
    13659.vim (Detached)
    1 Socket in /var/run/screen/S-root.


    [root@jindada ~]# screen -r vim    #或者通过id号


    [root@jindada ~]# screen -xr vim    #实时监控窗口的操作

     

    [detached from 13659.vim]


    ctrl + a + d    #临时退出

    exit   #真正退出

     

    五、系统平均负载


    [root@jindada ~]# top
    top - 11:54:48 up 1 day, 1:52, 3 users, load average: 0.00, 0.01, 0.05


    [root@jindada ~]# w
    11:54:59 up 1 day, 1:52, 3 users, load average: 0.00, 0.01, 0.05


    [root@jindada ~]# uptime
    11:55:09 up 1 day, 1:53, 3 users, load average: 0.00, 0.01, 0.05

     

    1分钟 5分钟 15分钟 系统的平均负载

    平均负载跟系统CPU的使用率没有太大关系


    在单位时间内,系统正在运行中的进程数或者不可中断的进程数量 进程的活跃数量


    跟CPU的核心数有关系


    当负载为2的时候

    核心数为4 50%

    核心数为2 100%

    核心数为1 200%

     

    当1分钟的值小于5分钟和15分钟的时候 说明你之前的平均负载过高,当前正在降低

    当1分钟跟5分钟和15分钟的值很近的时候,平均负载很稳定

    当1分钟的值大于5分钟和15分钟的时候,说明现在的负载正在慢慢的变大


    当值达到70% 就要开始分析问题

      

  • 相关阅读:
    Shell脚本 --- 正则表达式和文本处理工具
    python的eval、exec函数
    内置函数 Built-in Functions
    关于Python中的lambda
    Python中*args和**kwargs的区别
    Python基础-10-文件操作
    Python基础-09-内置函数
    Python基础-08-函数
    Python基础-07-集合
    Python基础-06-字典
  • 原文地址:https://www.cnblogs.com/jhno1/p/13439955.html
Copyright © 2011-2022 走看看