"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.5/littleutils/lsysinfo.c" (29 Oct 2021, 4859 Bytes) of package /linux/privat/littleutils-1.2.5.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lsysinfo.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.4_vs_1.2.5.

    1 /* lsysinfo:  Prints out various pieces of system information.
    2 
    3    Copyright (C) 2001-2021 by Brian E. Lindholm.
    4    This file is part of the littleutils utility set.
    5 
    6    The lsysinfo utility is free software; you can redistribute it and/or
    7    modify it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 3, or (at your option) any
    9    later version.
   10 
   11    The lsysinfo utility is distributed in the hope that it will be useful, but
   12    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   14    more details.
   15 
   16    You should have received a copy of the GNU General Public License along with
   17    the littleutils.  If not, see <https://www.gnu.org/licenses/>. */
   18 
   19 
   20 #include <config.h>
   21 
   22 #ifdef HAVE_STDIO_H
   23 # include <stdio.h>
   24 #endif
   25 #ifdef HAVE_UNISTD_H
   26 # include <unistd.h>
   27 #endif
   28 
   29 #ifdef HAVE_SYS_SYSINFO_H
   30 #include <sys/sysinfo.h>
   31 
   32 #if defined(__CYGWIN__)
   33 #define SYSINFO_SHIFT 8
   34 #else
   35 #define SYSINFO_SHIFT 20
   36 #endif
   37 
   38 int
   39 main (int argc, char *argv[])
   40 {
   41   struct sysinfo info;
   42   int rc;
   43 
   44   rc = sysinfo (&info);
   45   if (rc == 0)
   46     {
   47       fprintf (stdout, "sysinfo information:\n");
   48       fprintf (stdout, "  total RAM  = %5ld MiB\n", info.totalram >> SYSINFO_SHIFT);
   49       fprintf (stdout, "  free RAM   = %5ld MiB\n", info.freeram >> SYSINFO_SHIFT);
   50 #if !defined(__CYGWIN__)
   51       fprintf (stdout, "  shared RAM = %5ld MiB\n", info.sharedram >> SYSINFO_SHIFT);
   52       fprintf (stdout, "  buffer RAM = %5ld MiB\n", info.bufferram >> SYSINFO_SHIFT);
   53 #endif
   54       fprintf (stdout, "  total SWAP = %5ld MiB\n", info.totalswap >> SYSINFO_SHIFT);
   55       fprintf (stdout, "  free SWAP  = %5ld MiB\n", info.freeswap >> SYSINFO_SHIFT);
   56       fprintf (stdout, "  uptime = %ld seconds\n", info.uptime);
   57       fprintf (stdout, "  processes = %d\n", info.procs);
   58       fprintf (stdout, "  loadavg = %.3f, %.3f, %.3f\n", info.loads[0] / 65536.0,
   59         info.loads[1] / 65536.0, info.loads[2] / 65536.0);
   60     }
   61   else
   62     fprintf (stderr, "sysinfo error: bad sysinfo call\n");
   63 
   64   fprintf (stdout, "sysconf information:\n");
   65   fprintf (stdout, "  MEMORY = %ld MiB\n", (sysconf(_SC_PAGE_SIZE) >> 10) * (sysconf(_SC_PHYS_PAGES) >> 10));
   66   fprintf (stdout, "  PAGE_SIZE = %ld bytes\n", sysconf(_SC_PAGE_SIZE));
   67   fprintf (stdout, "  AVAIL_PHYS_PAGES = %ld\n", sysconf(_SC_AVPHYS_PAGES));
   68   fprintf (stdout, "  TOTAL_PHYS_PAGES = %ld\n", sysconf(_SC_PHYS_PAGES));
   69   fprintf (stdout, "  NUM_OF_PROCESSORS_CONF = %lu\n", sysconf(_SC_NPROCESSORS_CONF));
   70   fprintf (stdout, "  NUM_OF_PROCESSORS_ONLN = %lu\n", sysconf(_SC_NPROCESSORS_ONLN));
   71   fprintf (stdout, "  CLK_TCK = %lu\n", sysconf(_SC_CLK_TCK));
   72   fprintf (stdout, "  OPEN_MAX = %lu\n", sysconf(_SC_OPEN_MAX));
   73 
   74   return (0);
   75 }
   76 
   77 #elif defined(sun)
   78 #include <sys/systeminfo.h>
   79 
   80 int
   81 main (int argc, char *argv[])
   82 {
   83   char buf[1024];
   84   int count = 1024;
   85 
   86   fprintf (stdout, "sysinfo information:\n");
   87   sysinfo (SI_SYSNAME, buf, count);
   88   fprintf (stdout, "  SYSNAME = %s\n", buf);
   89   sysinfo (SI_HOSTNAME, buf, count);
   90   fprintf (stdout, "  HOSTNAME = %s\n", buf);
   91   sysinfo (SI_RELEASE, buf, count);
   92   fprintf (stdout, "  RELEASE = %s\n", buf);
   93   sysinfo (SI_VERSION, buf, count);
   94   fprintf (stdout, "  VERSION = %s\n", buf);
   95   sysinfo (SI_MACHINE, buf, count);
   96   fprintf (stdout, "  MACHINE = %s\n", buf);
   97   sysinfo (SI_ARCHITECTURE, buf, count);
   98   fprintf (stdout, "  ARCHITECTURE = %s\n", buf);
   99   sysinfo (SI_ISALIST, buf, count);
  100   fprintf (stdout, "  ISALIST = %s\n", buf);
  101   sysinfo (SI_PLATFORM, buf, count);
  102   fprintf (stdout, "  PLATFORM = %s\n", buf);
  103   sysinfo (SI_HW_PROVIDER, buf, count);
  104   fprintf (stdout, "  HW_PROVIDER = %s\n", buf);
  105   sysinfo (SI_HW_SERIAL, buf, count);
  106   fprintf (stdout, "  HW_SERIAL = %s\n", buf);
  107 
  108   fprintf (stdout, "sysconf information:\n");
  109   fprintf (stdout, "  NUM_OF_PROCESSORS_CONF = %lu\n", sysconf(_SC_NPROCESSORS_CONF));
  110   fprintf (stdout, "  NUM_OF_PROCESSORS_ONLN = %lu\n", sysconf(_SC_NPROCESSORS_ONLN));
  111   fprintf (stdout, "  PAGE_SIZE = %ld bytes\n", sysconf(_SC_PAGE_SIZE));
  112   fprintf (stdout, "  PHYS_PAGES = %ld\n", sysconf(_SC_PHYS_PAGES));
  113   fprintf (stdout, "  MEMORY = %ld MiB\n", (sysconf(_SC_PAGE_SIZE) >> 10) * (sysconf(_SC_PHYS_PAGES) >> 10));
  114 
  115   return (0);
  116 }
  117 
  118 #elif defined(DJGPP)
  119 
  120 int
  121 main (int argc, char *argv[])
  122 {
  123   fprintf (stdout, "sysconf information:\n");
  124   fprintf (stdout, "  CLK_TCK = %lu\n", sysconf(_SC_CLK_TCK));
  125   fprintf (stdout, "  OPEN_MAX = %lu\n", sysconf(_SC_OPEN_MAX));
  126   return (0);
  127 }
  128 
  129 #elif defined(__MINGW__)
  130 
  131 int
  132 main (int argc, char *argv[])
  133 {
  134   fprintf (stdout, "No sysinfo information available for MINGW\n");
  135   return (0);
  136 }
  137 
  138 #else
  139 
  140 int
  141 main (int argc, char *argv[])
  142 {
  143   fprintf (stdout, "No sysinfo information available for unknown system\n");
  144   return (0);
  145 }
  146 
  147 #endif