Linux系统上的进程查看及管理工具:
pstree , ps , pgrep , pkill , pidof ;
uptime , top ;
htop , vmstat , pmap , glances ;
dstat ;
kill , killall ;
job , bg , fg , nohup , nice , renice , …;
关键词:uptime, top;
1、uptime命令
命令说明:
uptime – Tell how long the system has been running.
[root@kouyuushinn ~]# uptime 09:06:53 up 3 days, 19:19, 4 users, load average: 0.00, 0.01, 0.05 字段解释(从左到右): 09:06:53 系统当前时间; up 3 days, 19:19 系统运行的时间长度; 4 users 当前系统的登录用户数; load average: 0.00, 0.01, 0.05 过去1分钟、5分钟、15分钟,在CPU上等待运行的队列长度;
显示系统启动时间:
~]# date -d “$(awk -F’ ‘ ‘{print $1}’ /proc/uptime) second ago” +”%Y-%m-%d %H:%M:%S”
显示系统运行时间:
~]# cat /proc/uptime | awk -F’ ‘ ‘{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf(“系统已运行:%d天%d时%d分%d秒”,run_days,run_hour,run_minute,run_second)}’
2、top命令
命令说明:
top – display Linux processes
[root@kouyuushinn ~]# top top - 09:14:13 up 3 days, 19:26, 4 users, load average: 0.02, 0.02, 0.05 第一行 Tasks: 149 total, 2 running, 147 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 : 998604 total, 142596 free, 130816 used, 725192 buff/cache 第四行 KiB Swap: 2097148 total, 2095032 free, 2116 used. 586284 avail Mem 第五行 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 第六行 1 root 20 0 125324 3484 2080 S 0.0 0.3 0:46.71 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 2 root 20 0 0 0 0 S 0.0 0.0 0:00.03 [kthreadd] 3 root 20 0 0 0 0 S 0.0 0.0 0:04.49 [ksoftirqd/0] 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H] 7 root rt 0 0 0 0 S 0.0 0.0 0:00.27 [migration/0] 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh] 9 root 20 0 0 0 0 R 0.0 0.0 0:11.12 [rcu_sched] 'top'命令显示的信息,从上至下,从左到右进行字段说明: -------------------------------------------------- 第一行:1>系统当前时间;2>系统已运行的时间长度;3>当前系统登录的用户数;4>系统平均负载,过去1分钟、5分钟、15分钟,在CPU上等待运行的队列长度; 第二行:1>总共运行多少进程;2>运行态进程数量;3>睡眠态进程数量;4>停止态进程数量;5>僵尸进程数量; 第三行:1>用户空间的进程占用CPU百分比;2>内核空间的进程占用CPU百分比;3>nice值调整后占用CPU的百分比;4>CPU空闲百分比;5>等待IO完成所消耗的时间; 6>处理硬件中断所消耗的CPU百分比;7>软件中断所消耗的CPU百分比;8>被虚拟化程序偷走的CPU时间百分比; 备注:'us'跟'sy'的比例值,一般是7:3,在系统忙碌时,CPU的时间主要需要提供给用户空间的进程; us, user : time running un-niced user processes sy, system : time running kernel processes ni, nice : time running niced user processes id, idle : time spent in the kernel idle handler wa, IO-wait : time waiting for I/O completion hi : time spent servicing hardware interrupts si : time spent servicing software interrupts st : time stolen from this vm by the hypervisor 第四行:1>总内存;2>空闲内存;3>已用内存;4>缓冲区/缓存区; 第五行:1>swap总空间;2>swap空闲空间;3>swap已用空间;4>可用swap空间; 第六行:1>PID;2>运行进程的用户;3>进程优先级;4>进程的nice值;5>虚拟内存集;6>常驻内存集;7>共享内存空间;8>进程当前状态; 9>CPU占用百分比;10>内存占用百分比;11>运行时长;12>启动进程的命令;
交互式命令:
——————-
首部信息显示与隐藏:
l : uptime信息;
t : tasks及CPU信息;
m : 内存信息;
排序:
P : 大写字母’P’,占据CPU百分比排序;
M :占据内存百分比排序;
T : 累积占用CPU时间排序;
退出命令: q;
修改刷新时间间隔:s 命令;
终止指定的进程 : k 命令;
常用选项:
————-
top -d # 指定刷新时间间隔,默认是3秒;
top -b 以时间间隔为单位,批次方式显示;
top -b -n # 以时间间隔为单位,指定显示多少批次;