Debian Codegraph @

listings/chapter-8/sysinfo.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <linux/kernel.h>
8 #include <linux/sys.h>
9 #include <stdio.h>
10 #include <sys/sysinfo.h>
11
12 int main ()
13 {
14 /* Conversion constants. */
15 const long minute = 60;
16 const long hour = minute * 60;
17 const long day = hour * 24;
18 const double megabyte = 1024 * 1024;
19 /* Obtain system statistics. */
20 struct sysinfo si;
21 sysinfo (&si);
22 /* Summarize intersting values. */
23 printf ("system uptime : %ld days, %ld:%02ld:%02ld\n",
24 si.uptime / day, (si.uptime % day) / hour,
25 (si.uptime % hour) / minute, si.uptime % minute);
26 printf ("total RAM : %5.1f MB\n", si.totalram / megabyte);
27 printf ("free RAM : %5.1f MB\n", si.freeram / megabyte);
28 printf ("process count : %d\n", si.procs);
29
30 return 0;
31 }