• 服务和进程管理(一)


    进程管理的三个主要任务:
            判断服务器健康状态(top)
            查看所有正在运行的进程(ps pstree)
            强制终止进程(kill pkill)

        1    ps    aux            查看当前系统所有运行的进程
                      a    显示前台所有进程
                      u    显示用户名
                      x    显示后台进程

                user:用户名
                  pid:进程id    PID    1    init    系统启动的第一个进程
              %CPU  CPU占用百分比
              %MEM 内存占用百分比
                 VSZ   虚拟内存占用量    KB
                 RSS  固定内存占有量
                   tty:登录终端            tty1-7    本地终端    1-6    字符    7图形    pts/0-5        alt+F1-F7
                 stat:状态    S:睡眠
                                     D:不可唤醒
                                     R:运行
                                     T:停止
                                     Z:僵死
                                     W:进入内存交换
                                     X:死掉的进程
                                     <:高优先级
                                     N:低优先级
                                     L:被锁进内存
                                     s:含子进程
                                     +:位于后台
                                     1:多线程
                   start:进程触发时间
                   time:占用CPU时间
                   command:进程本身
        2、pstree    查看进程树    -p    显示子进程和其ID号

        3、top(动态查看进程,具体案例在例子2)

        4、进程管理        (终止进程)
            kill   PID    结束单个进程
            -9    强制

            killall    -9    进程名    结束一类进程
            pkill    -9    进程名

            w        判断登录用户
            pkill    -9    -t    终端号        把某个终端登录的用户踢出
            pkill    -9    -t    tty1             把本地登录终端1登录用户踢出

    1. [root@centos ~]# ps aux
    2. USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    3. root         1  0.0  0.1   2900  1436 ?        Ss   01:28   0:02 /sbin/init
    4. root         2  0.0  0.0      0     0 ?        S    01:28   0:00 [kthreadd]
    5. root         3  0.0  0.0      0     0 ?        S    01:28   0:00 [migration/0]
    6. root         4  0.0  0.0      0     0 ?        S    01:28   0:00 [ksoftirqd/0]
    7. root         5  0.0  0.0      0     0 ?        S    01:28   0:00 [migration/0]
    8. root         6  0.0  0.0      0     0 ?        S    01:28   0:00 [watchdog/0]
    9. root         7  0.0  0.0      0     0 ?        S    01:28   0:00 [events/0]
    10. root         8  0.0  0.0      0     0 ?        S    01:28   0:00 [cgroup]
    11. root         9  0.0  0.0      0     0 ?        S    01:28   0:00 [khelper]
    12. root        10  0.0  0.0      0     0 ?        S    01:28   0:00 [netns]
    13. root        11  0.0  0.0      0     0 ?        S    01:28   0:00 [async/mgr]
    14. root        12  0.0  0.0      0     0 ?        S    01:28   0:00 [pm]
    15. root        13  0.0  0.0      0     0 ?        S    01:28   0:00 [sync_supers]
    16. root        14  0.0  0.0      0     0 ?        S    01:28   0:00 [bdi-default]
    17. root        15  0.0  0.0      0     0 ?        S    01:28   0:00 [kintegrityd/0]
    18. root        16  0.0  0.0      0     0 ?        S    01:28   0:00 [kblockd/0]
    19. root        17  0.0  0.0      0     0 ?        S    01:28   0:00 [kacpid]
    20. root        18  0.0  0.0      0     0 ?        S    01:28   0:00 [kacpi_notify]
    21. root        19  0.0  0.0      0     0 ?        S    01:28   0:00 [kacpi_hotplug]
    22. root        20  0.0  0.0      0     0 ?        S    01:28   0:00 [ata_aux]
    23. 654321root        21  0.0  0.0      0     0 ?        S    01:28   0:00 [ata_sff/0]
    24. root        22  0.0  0.0      0     0 ?        S    01:28   0:00 [ksuspend_usbd]
    25. root        23  0.0  0.0      0     0 ?        S    01:28   0:00 [khubd]
    26. root        24  0.0  0.0      0     0 ?        S    01:28   0:00 [kseriod]
    27. root        25  0.0  0.0      0     0 ?        S    01:28   0:00 [md/0]
    28. root        26  0.0  0.0      0     0 ?        S    01:28   0:00 [md_misc/0]
    29. root        27  0.0  0.0      0     0 ?        S    01:28   0:00 [linkwatch]
    30. root        28  0.0  0.0      0     0 ?        S    01:28   0:00 [khungtaskd]
    31. root        29  0.0  0.0      0     0 ?        S    01:28   0:00 [kswapd0]
    32. root        30  0.0  0.0      0     0 ?        SN   01:28   0:00 [ksmd]
    33. root        31  0.0  0.0      0     0 ?        S    01:28   0:00 [aio/0]
    34. root        32  0.0  0.0      0     0 ?        S    01:28   0:00 [crypto/0]
    35. root        37  0.0  0.0      0     0 ?        S    01:28   0:00 [kthrotld/0]
    36. root        38  0.0  0.0      0     0 ?        S    01:28   0:00 [pciehpd]
    37. root        40  0.0  0.0      0     0 ?        S    01:28   0:00 [kpsmoused]
    38. root        41  0.0  0.0      0     0 ?        S    01:28   0:00 [usbhid_resumer]
    39. root        71  0.0  0.0      0     0 ?        S    01:28   0:00 [kstriped]
    40. root       146  0.0  0.0      0     0 ?        S    01:28   0:00 [scsi_eh_0]
    41. root       147  0.0  0.0      0     0 ?        S    01:28   0:00 [scsi_eh_1]
    42. root       155  0.0  0.0      0     0 ?        S    01:28   0:00 [mpt_poll_0]
    43. root       156  0.0  0.0      0     0 ?        S    01:28   0:00 [mpt/0]
    44. root       157  0.0  0.0      0     0 ?        S    01:28   0:00 [scsi_eh_2]
    45. root       281  0.0  0.0      0     0 ?        S    01:28   0:00 [jbd2/sda5-8]
    46. root       282  0.0  0.0      0     0 ?        S    01:28   0:00 [ext4-dio-unwrit]
    47. root       292  0.0  0.0      0     0 ?        S    01:28   0:00 [flush-8:0]
    48. root       374  0.0  0.1   2768  1060 ?        S<s  01:28   0:00 /sbin/udevd -d
    49. root       632  0.0  0.0      0     0 ?        S    01:28   0:00 [vmmemctl]
    50. root       705  0.0  0.0      0     0 ?        S    01:28   0:00 [jbd2/sda1-8]
    51. root       706  0.0  0.0      0     0 ?        S    01:28   0:00 [ext4-dio-unwrit]
    52. root       707  0.0  0.0      0     0 ?        S    01:28   0:00 [jbd2/sda2-8]
    53. root       708  0.0  0.0      0     0 ?        S    01:28   0:00 [ext4-dio-unwrit]
    54. root       753  0.0  0.0      0     0 ?        S    01:28   0:00 [kauditd]
    55. root       963  0.0  0.0  12932   800 ?        S<sl 01:28   0:00 auditd
    56. root       989  0.0  0.1  36164  1556 ?        Sl   01:29   0:00 /sbin/rsyslogd -i /var/run/syslogd.
    57. rpc       1031  0.0  0.0   2576   800 ?        Ss   01:29   0:00 rpcbind
    58. rpcuser   1049  0.0  0.1   2840  1268 ?        Ss   01:29   0:00 rpc.statd
    59. dbus      1104  0.0  0.1  13372  1148 ?        Ssl  01:29   0:00 dbus-daemon --system
    60. root      1121  0.0  0.2  13328  2756 ?        Ss   01:29   0:00 cupsd -C /etc/cups/cupsd.conf
    61. root      1146  0.0  0.0   2020   596 ?        Ss   01:29   0:00 /usr/sbin/acpid
    62. 68        1155  0.0  0.4  16932  4172 ?        Ssl  01:29   0:00 hald
    63. root      1156  0.0  0.1   3980  1140 ?        S    01:29   0:00 hald-runner
    64. root      1185  0.0  0.1   4052  1052 ?        S    01:29   0:00 hald-addon-input: Listening on /dev
    65. 68        1199  0.0  0.0   3644  1008 ?        S    01:29   0:00 hald-addon-acpi: listening on acpid
    66. root      1219  0.0  0.1  29008  1584 ?        Ssl  01:29   0:00 automount --pid-file /var/run/autof
    67. root      1239  0.0  0.1   8944  1044 ?        Ss   01:29   0:00 /usr/sbin/sshd
    68. root      1315  0.0  0.2  12964  2604 ?        Ss   01:29   0:00 /usr/libexec/postfix/master
    69. postfix   1323  0.0  0.2  13040  2564 ?        S    01:29   0:00 pickup -l -t fifo -u
    70. postfix   1324  0.0  0.2  13108  2608 ?        S    01:29   0:00 qmgr -l -t fifo -u
    71. root      1339  0.0  0.0   6460   868 ?        Ss   01:29   0:00 /usr/sbin/abrtd
    72. root      1347  0.0  0.1   7144  1280 ?        Ss   01:29   0:01 crond
    73. root      1358  0.0  0.0   2988   468 ?        Ss   01:29   0:00 /usr/sbin/atd
    74. root      1370  0.0  0.0   8784   568 ?        Ss   01:29   0:00 /usr/sbin/certmonger -S -p /var/run
    75. root      1383  0.0  0.2   5624  2636 ?        Ss   01:29   0:00 login -- root     
    76. root      1385  0.0  0.0   2008   476 tty2     Ss+  01:29   0:00 /sbin/mingetty /dev/tty2
    77. root      1387  0.0  0.0   2008   476 tty3     Ss+  01:29   0:00 /sbin/mingetty /dev/tty3
    78. root      1389  0.0  0.0   2008   500 tty4     Ss+  01:29   0:00 /sbin/mingetty /dev/tty4
    79. root      1394  0.0  0.0   2008   476 tty5     Ss+  01:29   0:00 /sbin/mingetty /dev/tty5
    80. root      1398  0.0  0.0   2008   472 tty6     Ss+  01:29   0:00 /sbin/mingetty /dev/tty6
    81. root      1399  0.0  0.1   3424  1816 ?        S<   01:29   0:00 /sbin/udevd -d
    82. root      1400  0.0  0.1   3424  1816 ?        S<   01:29   0:00 /sbin/udevd -d
    83. root      1436  0.0  0.2  22616  2832 ?        Sl   01:45   0:00 /usr/sbin/console-kit-daemon --no-d
    84. root      1503  0.0  0.1   8024  1684 tty1     Ss+  01:45   0:00 -bash
    85. root      1555  0.0  0.3  11888  3352 ?        Ss   01:53   0:00 sshd: root@pts/0 
    86. root      1560  0.0  0.1   6876  1692 pts/0    Ss+  01:54   0:00 -bash
    87. root      1623  0.0  0.3  11888  3348 ?        Ss   02:04   0:00 sshd: root@pts/1 
    88. root      1627  0.0  0.1   6876  1608 pts/1    Ss+  02:04   0:00 -bash
    89. root      1650  0.0  0.3  11888  3352 ?        Ss   02:07   0:00 sshd: root@pts/2 
    90. root      1656  0.0  0.1   6876  1676 pts/2    Ss+  02:07   0:00 -bash
    91. root      1715  0.0  0.3  11888  3352 ?        Ss   02:19   0:00 sshd: root@pts/3 
    92. root      1724  0.0  0.1   6876  1648 pts/3    Ss   02:20   0:00 -bash
    93. root      1819 10.0  0.1   6552  1052 pts/3    R+   02:48   0:00 ps aux
    94. [root@centos ~]# who
    95. root     tty1         2014-09-16 01:45
    96. root     pts/0        2014-09-16 01:54 (192.168.20.28)
    97. root     pts/1        2014-09-16 02:04 (192.168.20.28)
    98. root     pts/2        2014-09-16 02:07 (192.168.20.28)
    99. root     pts/3        2014-09-16 02:20 (192.168.20.28)

    3、top(显示的内容是动态的,每隔3秒更新一次)

    第一行:系统当前时间        系统持续时间        登录用户    1,5,15分钟之前的平均负载
    第二行:进程总数
    第三行:CPU占用率    %id(空闲百分比,一般标准不小于20%)
    第四行:内存使用:    总共    使用    空闲    缓存
    第五行:swap使用    

    操作命令:    M    内存排序
                          P    CPU排序
                          q    退出
    1. [root@centos ~]# top
    1. top - 03:42:56 up  2:14, 10 users,  load average: 0.00, 0.00, 0.00
    2. Tasks: 110 total,   1 running, 109 sleeping,   0 stopped,   0 zombie
    3. Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st
    4. Mem:   1030532k total,   199200k used,   831332k free,    31036k buffers
    5. Swap:   524280k total,        0k used,   524280k free,    68760k cached
    6.   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                               
    7.  2551 apache    20   0 36000 7024 1804 S  0.3  0.7   0:00.03 httpd                                  
    8.  2593 root      20   0 11888 3352 2604 S  0.3  0.3   0:00.24 sshd                                   
    9.  2616 root      20   0  2688 1092  868 R  0.3  0.1   0:00.24 top                                    
    10.     1 root      20   0  2900 1436 1216 S  0.0  0.1   0:02.12 init                                   
    11.     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                               
    12.     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                            
    13.     4 root      20   0     0    0    0 S  0.0  0.0   0:00.05 ksoftirqd/0                            
    14.     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                            
    15.     6 root      RT   0     0    0    0 S  0.0  0.0   0:00.16 watchdog/0                             
    16.     7 root      20   0     0    0    0 S  0.0  0.0   0:00.63 events/0                               
    17.     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                 
    18.     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                
    19.    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns                                  
    20.    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                              
    21.    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                     
    22.    13 root      20   0     0    0    0 S  0.0  0.0   0:00.08 sync_supers                            
    23.    14 root      20   0     0    0    0 S  0.0  0.0   0:00.08 bdi-default                            
    24.    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0                          
    25.    16 root      20   0     0    0    0 S  0.0  0.0   0:00.32 kblockd/0                              
    26.    17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid                                 

    服务:
    启动
    自启动

    源码包不能被所有的命令找到






    php是世界上最好的编程语言,没有之一
  • 相关阅读:
    (转)SGI STL中list的sort函数实现
    (转)OpenCv与Qt的结合,几种方法的比较
    (转)typeid详解
    转: C++藏书阁
    (转)Qt多线程编程
    (转)C/C++ 各种计时函数总结
    【转载】深入 Facebook 消息应用服务器
    ubuntu LAMP本地环境配置
    视频: 英语口音纠正课程
    【转载】安装 JDK1.6 / java 1.6 (linux, ubuntu, windows)
  • 原文地址:https://www.cnblogs.com/lookphp/p/4683067.html
Copyright © 2020-2023  润新知