1、uptime命令
uptime 命令是监控系统性能最常用的一个命令,主要是来统计系统当前的运行状态输出信息依次是:系统现在的时间,系统从上次开机到现在运行了多长时间,系统当前有多少个登录用户,系统在一分钟内、5 分钟内、15 分钟内的平均负载
注意点:如果load average 值长期大于系统CPU 的个数则说明CPU 很繁忙,负载很高,可能会影响系统性能。
[root@Beta-nginx test1]# uptime
15:05:20 up 28 days, 23:07, 1 user, load average: 0.00, 0.00, 0.00
[root@Beta-nginx test1]# uptime -V
procps version 3.2.8
[root@Beta-nginx test1]#
2、ps命令
ps 命令就是最基本同时也是非常强大的进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等.总之大部分信息都是可以通过执行该命令得到的。
Centos上进程有5种状态:
1. 运行(正在运行或在运行队列中等待)
2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号)
3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生)
4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放)
5. 停止(进程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU信号后停止运行运行)
ps工具标识进程的5种状态码:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
名称:ps
使用权限:所有使用者
使用方式:ps [options] [–help]
说明:显示当前进程 (process) 的状态
参数:
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义
-aux 显示所有包含其他使用者的行程
[root@Beta-nginx test1]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 19356 1520 ? Ss Mar30 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S Mar30 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Mar30 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S Mar30 0:04 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Mar30 0:00 [migration/0]
root 6 0.0 0.0 0 0 ? S Mar30 0:04 [watchdog/0]
root 7 0.0 0.0 0 0 ? S Mar30 0:00 [migration/1]
root 8 0.0 0.0 0 0 ? S Mar30 0:00 [migration/1]
root 9 0.0 0.0 0 0 ? S Mar30 0:03 [ksoftirqd/1]
root 10 0.0 0.0 0 0 ? S Mar30 0:04 [watchdog/1]
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
USER: 进程拥有者
PID: pid 进程id
%CPU: 进程所占用的 CPU 使用率
%MEM: 占用的内存的使用率
VSZ: 占用的虚拟内存大小
RSS: 占用的内存大小
TTY: 终端
STAT: 该行程的状态:
START: 行程开始时间
TIME: 执行的时间
COMMAND:所执行的指令
-ef
[root@Beta-nginx test1]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar30 ? 00:00:01 /sbin/init
root 2 0 0 Mar30 ? 00:00:00 [kthreadd]
root 3 2 0 Mar30 ? 00:00:00 [migration/0]
root 4 2 0 Mar30 ? 00:00:04 [ksoftirqd/0]
root 5 2 0 Mar30 ? 00:00:00 [migration/0]
root 6 2 0 Mar30 ? 00:00:04 [watchdog/0]
root 7 2 0 Mar30 ? 00:00:00 [migration/1]
root 8 2 0 Mar30 ? 00:00:00 [migration/1]
root 9 2 0 Mar30 ? 00:00:03 [ksoftirqd/1]
root 10 2 0 Mar30 ? 00:00:04 [watchdog/1]
找到用户进程ID后可以使用kill -9杀死进程
grep过滤
[root@localhost admin]# ps -ef|grep httpd
root 1080 1 0 Apr27 ? 00:00:01 /usr/sbin/httpd -DFOREGROUND
apache 1630 1080 0 Apr27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1631 1080 0 Apr27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1632 1080 0 Apr27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1634 1080 0 Apr27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1635 1080 0 Apr27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 9842 2773 0 00:44 pts/0 00:00:00 grep --color=auto httpd
把ps的查询结果通过管道给grep查找包含特定字符串的进程。管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。
pgrep
[root@localhost admin]# pgrep httpd
1080
1630
1631
1632
1634
1635