linux已开机时间 系统信息
linux 查看系统运行时间 (从开机当现在的开机时间)
1.uptime命令
输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.00
2.查看/proc/uptime文件计算系统启动时间
cat /proc/uptime
输出: 5113396.94 575949.85
第一数字即是系统已运行的时间5113396.94 秒,运用系统工具date即可算出系统启动时间
代码:
date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
输出: 2008-11-09 11:50:31
3.查看/proc/uptime文件计算系统运行时间
代码:
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)}'
输出:系统已运行:59天4时13分9秒
这样你就能轻松地应用Linux查看系统时间。
c代码:
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
};
#include <stdio.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <linux/unistd.h> /* for _syscallX macros/related stuff */
#include <linux/kernel.h> /* for struct sysinfo */
#include <sys/sysinfo.h> long get_uptime()
{
struct sysinfo s_info;
int error;
error = sysinfo(&s_info);
if(error != 0)
{
printf("code error = %d\n", error);
}
return s_info.uptime;
} long out_sys(){
/* Conversion constants. */
const long minute = 60;
const long hour = minute * 60;
const long day = hour * 24;
const double megabyte = 1024 * 1024;
/* Obtain system statistics. */
struct sysinfo si;
sysinfo (&si);
/* Summarize interesting values. */
printf ("system uptime : %ld days, %ld:%02ld:%02ld\n",
si.uptime / day, (si.uptime % day) / hour,
(si.uptime % hour) / minute, si.uptime % minute);
printf ("total RAM : %5.1f MB\n", si.totalram / megabyte);
printf ("free RAM : %5.1f MB\n", si.freeram / megabyte);
printf ("process count : %d\n", si.procs);
} int main(int argc, char* argv[]) {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
printf("tv_sec=%llu tv_nsec=%llu\n uptime time:%llu\n",
(unsigned long long)t.tv_sec,
(unsigned long long)t.tv_nsec,
get_uptime()); out_sys();
return 0;
}
linux已开机时间 系统信息的更多相关文章
- 笔记:查看linux系统开机时间
[root@localhost ~]# uptime -s -- :: 通过命令uptime -s 查看系统开机时间
- Linux 系统开机时间及当前时间
最近一次系统开机时间:date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M ...
- Linux查看系统开机时间
有时候需要查看Linux系统运行了多久时间,此时需要知道上次开机启动时间: 有时候由于断电或供电故障突然停机,需要查看Linux开机时间/重启时间: 下面总结一些查看Linux开机关机时间的方法(非 ...
- 查看linux系统的开机时间/重启历史记录
查看linux系统的开机时间/重启历史记录1.who -b命令[root@rusky opt]# who -b ---查看最后一次(上次)系统启动的时间 system boot Dec 27 05:0 ...
- 显示linux开机时间的脚本
最初的讨论是linux吧吧友@九十钩圈凯_ 发布的主题贴<加到自启动可以看开机时间的玩意> 并给出显示开机秒数的shell语句 [shell] [ $_UTED = 0 ] || noti ...
- 转载: Linux查看系统开机时间
转自: https://www.cnblogs.com/kerrycode/p/3759395.html 查看Linux系统运行了多久时间,此时需要知道上次开机启动时间: 有时候由于断电或供电故障突然 ...
- Linux查看系统开机时间(转)
1.who命令查看 who -b查看最后一次系统启动的时间. who -r查看当前系统运行时间 2.last reboot last reboot可以看到Linux系统历史启动的时间. 重启一下操作 ...
- windows中查看开机时间
windows中查看开机时间 在windows下可以使用systeminfo命令来查看. 下面是网站摘录的关于windows启动了多长时间的内容 1. windows系统可以查看从开机到现在共 ...
- 从零开始学Linux[一]:基本命令:系统信息、目录、文件、文件编辑
摘要:linux基础学习:系统信息.目录.文件查找.文件操作.查看文件内容及大小.软链接.VIM使用. 现在Linux的使用非常普遍.对于一个小白来说,满屏幕的字母,看起来就是一头雾水~ 目前由于 ...
随机推荐
- [HAOI2017]方案数[组合计数、容斥、dp]
题意 题目链接 分析 先考虑没有障碍怎么做,定义 f(i,j,k) 每一维走了 i,j,k 位的方案数,转移乘个组合数即可. 现在多了一些障碍,考虑容斥.实际我们走过的点都有严格的大小关系,所以先把所 ...
- SpringMVC环境搭建——HelloWorld
1.新建Maven Web 工程: 2.添加相关的依赖包(Spring MVC.tomcat插件等),具体的pom.xml文件如下 <project xmlns="http://mav ...
- D. Too Easy Problems
链接 [http://codeforces.com/group/1EzrFFyOc0/contest/913/problem/D] 题意 给你n个题目,考试时间T,对于每个问题都有一个ai,以及解决所 ...
- 11.13 Daily Scrum
今天在实现餐厅列表时,原来使用的百度地图poi搜索接口无法返回餐厅的具体信息. 经过一番周折,找到了一个返回餐厅url的接口.我们调整了一下实现,在点击餐厅列表的某一项点击直接跳到和该餐厅信息有关的网 ...
- 软件工程M1/M2总结及阅读作业总结
一.软件工程M1/M2总结 写下这篇总结的时候,我们的软件项目尚未完工.虽然尝试申请了延期答辩,但最终未能成功.这意味着,我们的项目能否正常发布已经处于了一个微妙的状态.可能可以,也可能不可以.只能尽 ...
- Minor GC vs Major GC vs Full GC
http://www.importnew.com/15820.html https://plumbr.io/blog/garbage-collection/minor-gc-vs-major-gc-v ...
- 关于splice()方法,slice() 、split()方法讲解,reverse()方法、replace()方法
1.slice() 方法可从已有的数组中返回选定的元素. 语法 arrayObject.slice(start,end) 参数 描述 start 必需.规定从何处开始选取.如果是负数,那么它规定从数组 ...
- [转帖]GitHub上整理的一些工具
GitHub上整理的一些工具 技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddit:同上 MSDN:微软相关的官方技术集中地,主要是文档类 inf ...
- 关于windows内存的一些简单看法
1. 公司的产品有一个检查windows操作系统的功能,验证是否满足 只能客户端 的运行需求: 这里面的可用虚拟内存是128T 感觉非常奇怪了. 然后自己想了下128T 是 2的 47次方 猜想是不是 ...
- [转]能用HTML/CSS解决的问题就不要使用JS
原文链接:http://www.codeceo.com/article/html-css-not-js.html 为什么说能使用html/css解决的问题就不要使用JS呢?两个字,因为简单.简单就意味 ...