int uptime();
int main() { time_t cutime = uptime(); time_t starttime = time((time_t *)NULL) - cutime; printf("Uptime is %d sec\n", (unsigned int)cutime); printf("Booting time is %s\n",time2str(starttime, "y/m/d/ D h:mi:s")); return 0; }
# ./uptime Uptime is 55489 sec Booting time is 2004/02/01/ 일 01:50:42
#include <stdio.h> #include <time.h> #include "time2str.h" #ifdef _SOLARIS_ #include <kstat.h> #endif #include <stdio.h> int uptime() { double stime; double idletime; #ifdef _LINUX_ char buf[36]; FILE *fp; if ((fp = fopen("/proc/uptime", "r")) == NULL) { return -1; } fgets(buf, 36, fp); sscanf(buf, "%lf %lf", &stime, &idletime); fclose(fp); return (int)stime; #endif #ifdef _SOLARIS_ kstat_ctl_t *kc; kstat_t *ks; kid_t kid; kstat_named_t *named; int i; kc = kstat_open(); if(kc == NULL) { perror("kstat_open"); exit(0); } ks = kstat_lookup(kc, "unix", -1, "system_misc"); kid = kstat_read(kc, ks, NULL); named = kstat_data_lookup(ks, "lbolt"); return (named->value.ul)/100; #endif }
# gcc -o test uptime.c -lksat -D_SOLARIS_
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
Contents
설명
사용방법
코드
컴파일
변경사항
Recent Posts
Archive Posts
Tags