码迷,mamicode.com
首页 > 系统相关 > 详细

每周一个linux命令之---uptime详解

时间:2018-09-18 16:12:58      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:ken   记忆   more   解释   inf   提高   sys   some   pre   

每周一个linux命令之---uptime详解

linux命令 uptime详解


引言:从今天开始,每周更新一个对程序员有用的linux命令,我真的没敢写每天一个,我怕我坚持不下去,每周一个还是可以的。既然每周一个了,就肯定不能拿ls,chmod这种命令来凑数了。降低数量,保障质量。与大家共勉。

进入正题

uptime

我们先来看一下命令执行结果

11:10:42 up 4 days, 19:23,  2 users,  load average: 3.17, 3.45, 3.65

我们来分组解释一下,大概分成一下几个部分

  • 系统当前时间 11:10:42
  • up 4 days, 19:23 从上次启动开始系统运行的时间
  • 2 users 注意这里实际是连接数量,可以自己测试出来,同一用户多个连接的时候算多个
  • load average: 3.17, 3.45, 3.65 这是重头戏,分别描述了1分钟5分钟15分钟内系统平均负载

我们使用man uptime命令进行查询uptime的说明如下(man命令不了解的稍微百度一下就明白,这是一个类似手册的功能)

注:一般我们使用 uptime -h 即命令加-h或--help的形式得到的是比较简单的帮助文档,而man命令一般会给出更详细的解释,不过一般都是英文的,其实也没有太难的词语希望大家坚持英文阅读。提高技术水平的同时也潜移默化的提高了英语水平

uptime  gives  a  one  line display of the following information.
       The current time, how long the system has been running, how  many
       users  are  currently logged on, and the system load averages for
       the past 1, 5, and 15 minutes.

       This is the same information contained in the  header  line  dis‐
       played by w(1).

       System  load averages is the average number of processes that are
       either in a runnable or uninterruptable state.  A  process  in  a
       runnable state is either using the CPU or waiting to use the CPU.
       A process in  uninterruptable  state  is  waiting  for  some  I/O
       access,  eg  waiting  for  disk.  The averages are taken over the
       three time intervals.  Load averages are not normalized  for  the
       number of CPUs in a system, so a load average of 1 means a single
       CPU system is loaded all the time while on  a  4  CPU  system  it
       means it was idle 75% of the time.

当然我知道大部分童鞋是不想看那么长串的英文的,我翻译了一下如下:

uptime 在一行中给了如下信息:当前时间,系统已经运行了多久,多少用户连接目前正在使用系统,系统在过去1,5,15分钟内的平均负载。
这与w(1)显示的标题行中包含相同的信息。
系统负载平均值是处于可运行或不可中断状态的平均进程数。 进程在可运行状态是指进程正在使用CPU或等待使用CPU。 处于不可中断状态的进程是指的进程正在等待某些I/O访问,例如等待磁盘。 平均值是在三个时间间隔内取得的。 对于系统中的CPU数量,负载平均值没有标准化,因此负载平均值为1意味着单个CPU系统一直在加载,而在4 CPU系统上,这意味着它在75%的时间内处于空闲状态。

这里我们做一个比喻便于理解,我们把处于可运行或不可中断状态的的平均进程数量比喻成货物数量,而cpu可以理解为传送带。货物数量是1个的话,如果只有一条传送带,那么传送带就是满负荷运行,如果有4个传送带,那么就有三条空闲(即上文说的75%空闲)。平均负载就可以理解为一段时间内的平均货物数量。

接下来我们学习一下uptime可携带的参数

OPTIONS
       -p, --pretty
              show uptime in pretty format//以比较友好的格式输出

       -h, --help
              display this help text//显示帮助选项

       -s, --since
              system up since, in yyyy-mm-dd HH:MM:SS format//系统启动时间

       -V, --version
              display version information and exit//版本信息

运行结果如下


@dev1:~$ uptime -p
up 4 days, 22 hours, 38 minutes
@dev1:~$ uptime -s
2018-09-13 15:47:04
@dev1:~$ uptime -V
uptime from procps-ng 3.3.10
@dev1:~$ uptime -h

Usage:
 uptime [options]

Options:
 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

For more details see uptime(1).

下面顺便提一下怎么查系统的cpu核心数量。(方法有很多种,我觉得这种最好记忆)

lscpu

这个命令应该是比较好记的,毕竟ls,cpu这两个我们都记得了。
这里面显示了很多选项。其中cpu(s):数量表明了cpu的个数。如下图

Architecture:          x86_64 //cpu架构
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian//小端(低位字节存储在内存的低地址端 intel的cpu一般是小端,amd的一般是大端 Big Endian)
CPU(s):                4//cpu数量

其他参数以后再讲吧。一篇文章太长了不利于学习和记忆。

每周一个linux命令之---uptime详解

标签:ken   记忆   more   解释   inf   提高   sys   some   pre   

原文地址:https://www.cnblogs.com/vinter/p/9668896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!