Linux查看开机运行时间的多种方法,linux查看开机运行


这篇文章主要介绍了Linux查看开机运行时间的多种方法,本文讲解了uptime命令、查看/proc/uptime文件计算系统启动时间、查看/proc/uptime文件计算系统运行时间、查看进程运行时间等方法,需要的朋友可以参考下

1. uptime命令

代码如下:
homer@ubuntu:~$ uptime
19:34:40 up 4 days, 4:18, 6 users, load average: 0.00, 0.01, 0.05

它依次显示:系统当前时间、系统已经运行了多长时间、目前有多少登陆用户、系统在过去的1分钟、5分钟、15分钟内的平均负载。

19:34:40  表示系统当前时刻

4 days,  4:18 表示系统运行持续时间,即累计持续运行了 4天4小时18分钟

查看用户: who

代码如下:
homer@ubuntu:~$ who
homer tty7 2014-04-10 15:20
homer pts/0 2014-04-10 15:22 (:0)
homer pts/2 2014-04-10 16:03 (:0)
homer pts/3 2014-04-10 19:46 (:0)
homer pts/4 2014-04-11 17:34 (:0)
homer pts/6 2014-04-14 19:34 (172.27.22.17)

2. 查看/proc/uptime文件,计算系统启动时间

代码如下:
homer@ubuntu:~$ cat /proc/uptime
361481.06 1412691.64
输出: 361481.06 1412691.64

第一数字即是系统已运行的时间5113396.94 秒

1) 计算器计算: 361481.06 / 3600 / 24 = 25.1028(天)

2) 运用系统工具date计算出系统启动时间

代码如下:
homer@ubuntu:~$ date -d “$(awk -F. ‘{print $1}’ /proc/uptime) second ago” +”%Y-%m-%d %H:%M:%S”
2014-04-10 15:16:41

3. 查看/proc/uptime文件,计算系统运行时间

代码如下:
homer@ubuntu:~$ 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 秒\n”,run_days,run_hour,run_minute,run_second)}’

系统已运行:4天4时30分4秒

输出:系统已运行:4天4时30分4秒

4.查看进程运行时间:

1)进程启动时间:

代码如下:
root@ubuntu:/# ps -eo lstart
STARTED
Thu Apr 10 15:16:40 2014
Thu Apr 10 15:16:40 2014
Thu Apr 10 15:16:40 2014

2)进程运行时间:

代码如下:
root@ubuntu:/# ps -eo etime
ELAPSED
4-04:50:20
4-04:50:20
4-04:50:20

 

3)查看进程启动/运行时间:

代码如下:
root@ubuntu:/# ps -eo uid,pid,ppid,cmd,lstart,etime
UID PID PPID CMD STARTED ELAPSED
0 1 0 /sbin/init Thu Apr 10 15:16:40 2014 4-04:51:50
0 2 0 [kthreadd] Thu Apr 10 15:16:40 2014 4-04:51:50
0 3 2 [ksoftirqd/0] Thu Apr 10 15:16:40 2014 4-04:51:50
0 5 2 [kworker/u:0] Thu Apr 10 15:16:40 2014 4-04:51:50
0 6 2 [migration/0] Thu Apr 10 15:16:40 2014 4-04:51:50
0 7 2 [watchdog/0] Thu Apr 10 15:16:40 2014 4-04:51:50


 5.图形化工具:

bootchart 是一个用于linux启动过程性能分析的开源软件工具,在系统启动过程自动收集CPU占用率、进程等信息,并以图形方式显示分析结果,可用作指导优化系统启动过程。

Debian/Ubuntu 上安装查看bootchart步骤:

1) 安装 sudo apt-get install bootchart

2) 重启系统: sudo reboot

3) 生成的bootchart图片会保存在 /var/log/bootchart/ 目录下,用 GNOME image viewer打开

代码如下:
eog /var/log/bootchart/ubuntu-precise-20140414-1.png

4) 生成的bootchart图片如下:


相关内容