"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.4/littleutils/lsysinfo.c" (28 Mar 2021, 4837 Bytes) of package /linux/privat/littleutils-1.2.4.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.

    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 #include <stdio.h>
   23 #ifdef HAVE_UNISTD_H
   24 # include <unistd.h>
   25 #endif
   26 
   27 #if defined(HAVE_SYS_SYSINFO_H)
   28 #include <sys/sysinfo.h>
   29 
   30 #if defined(__CYGWIN__)
   31 #define SYSINFO_SHIFT 8
   32 #else
   33 #define SYSINFO_SHIFT 20
   34 #endif
   35 
   36 int
   37 main (int argc, char *argv[])
   38 {
   39   struct sysinfo info;
   40   int rc;
   41 
   42   rc = sysinfo (&info);
   43   if (rc == 0)
   44     {
   45       fprintf (stdout, "sysinfo information:\n");
   46       fprintf (stdout, "  total RAM  = %5ld MiB\n", info.totalram >> SYSINFO_SHIFT);
   47       fprintf (stdout, "  free RAM   = %5ld MiB\n", info.freeram >> SYSINFO_SHIFT);
   48 #if !defined(__CYGWIN__)
   49       fprintf (stdout, "  shared RAM = %5ld MiB\n", info.sharedram >> SYSINFO_SHIFT);
   50       fprintf (stdout, "  buffer RAM = %5ld MiB\n", info.bufferram >> SYSINFO_SHIFT);
   51 #endif
   52       fprintf (stdout, "  total SWAP = %5ld MiB\n", info.totalswap >> SYSINFO_SHIFT);
   53       fprintf (stdout, "  free SWAP  = %5ld MiB\n", info.freeswap >> SYSINFO_SHIFT);
   54       fprintf (stdout, "  uptime = %ld seconds\n", info.uptime);
   55       fprintf (stdout, "  processes = %d\n", info.procs);
   56       fprintf (stdout, "  loadavg = %.3f, %.3f, %.3f\n", info.loads[0] / 65536.0,
   57         info.loads[1] / 65536.0, info.loads[2] / 65536.0);
   58     }
   59   else
   60     fprintf (stderr, "sysinfo error: bad sysinfo call\n");
   61 
   62   fprintf (stdout, "sysconf information:\n");
   63   fprintf (stdout, "  MEMORY = %ld MiB\n", (sysconf(_SC_PAGE_SIZE) >> 10) * (sysconf(_SC_PHYS_PAGES) >> 10));
   64   fprintf (stdout, "  PAGE_SIZE = %ld bytes\n", sysconf(_SC_PAGE_SIZE));
   65   fprintf (stdout, "  AVAIL_PHYS_PAGES = %ld\n", sysconf(_SC_AVPHYS_PAGES));
   66   fprintf (stdout, "  TOTAL_PHYS_PAGES = %ld\n", sysconf(_SC_PHYS_PAGES));
   67   fprintf (stdout, "  NUM_OF_PROCESSORS_CONF = %lu\n", sysconf(_SC_NPROCESSORS_CONF));
   68   fprintf (stdout, "  NUM_OF_PROCESSORS_ONLN = %lu\n", sysconf(_SC_NPROCESSORS_ONLN));
   69   fprintf (stdout, "  CLK_TCK = %lu\n", sysconf(_SC_CLK_TCK));
   70   fprintf (stdout, "  OPEN_MAX = %lu\n", sysconf(_SC_OPEN_MAX));
   71 
   72   return (0);
   73 }
   74 
   75 #elif defined(sun)
   76 #include <sys/systeminfo.h>
   77 
   78 int
   79 main (int argc, char *argv[])
   80 {
   81   char buf[1024];
   82   int count = 1024;
   83 
   84   fprintf (stdout, "sysinfo information:\n");
   85   sysinfo (SI_SYSNAME, buf, count);
   86   fprintf (stdout, "  SYSNAME = %s\n", buf);
   87   sysinfo (SI_HOSTNAME, buf, count);
   88   fprintf (stdout, "  HOSTNAME = %s\n", buf);
   89   sysinfo (SI_RELEASE, buf, count);
   90   fprintf (stdout, "  RELEASE = %s\n", buf);
   91   sysinfo (SI_VERSION, buf, count);
   92   fprintf (stdout, "  VERSION = %s\n", buf);
   93   sysinfo (SI_MACHINE, buf, count);
   94   fprintf (stdout, "  MACHINE = %s\n", buf);
   95   sysinfo (SI_ARCHITECTURE, buf, count);
   96   fprintf (stdout, "  ARCHITECTURE = %s\n", buf);
   97   sysinfo (SI_ISALIST, buf, count);
   98   fprintf (stdout, "  ISALIST = %s\n", buf);
   99   sysinfo (SI_PLATFORM, buf, count);
  100   fprintf (stdout, "  PLATFORM = %s\n", buf);
  101   sysinfo (SI_HW_PROVIDER, buf, count);
  102   fprintf (stdout, "  HW_PROVIDER = %s\n", buf);
  103   sysinfo (SI_HW_SERIAL, buf, count);
  104   fprintf (stdout, "  HW_SERIAL = %s\n", buf);
  105 
  106   fprintf (stdout, "sysconf information:\n");
  107   fprintf (stdout, "  NUM_OF_PROCESSORS_CONF = %lu\n", sysconf(_SC_NPROCESSORS_CONF));
  108   fprintf (stdout, "  NUM_OF_PROCESSORS_ONLN = %lu\n", sysconf(_SC_NPROCESSORS_ONLN));
  109   fprintf (stdout, "  PAGE_SIZE = %ld bytes\n", sysconf(_SC_PAGE_SIZE));
  110   fprintf (stdout, "  PHYS_PAGES = %ld\n", sysconf(_SC_PHYS_PAGES));
  111   fprintf (stdout, "  MEMORY = %ld MiB\n", (sysconf(_SC_PAGE_SIZE) >> 10) * (sysconf(_SC_PHYS_PAGES) >> 10));
  112 
  113   return (0);
  114 }
  115 
  116 #elif defined(DJGPP)
  117 
  118 int
  119 main (int argc, char *argv[])
  120 {
  121   fprintf (stdout, "sysconf information:\n");
  122   fprintf (stdout, "  CLK_TCK = %lu\n", sysconf(_SC_CLK_TCK));
  123   fprintf (stdout, "  OPEN_MAX = %lu\n", sysconf(_SC_OPEN_MAX));
  124   return (0);
  125 }
  126 
  127 #elif defined(__MINGW__)
  128 
  129 int
  130 main (int argc, char *argv[])
  131 {
  132   fprintf (stdout, "No sysinfo information available for MINGW\n");
  133   return (0);
  134 }
  135 
  136 #else
  137 
  138 int
  139 main (int argc, char *argv[])
  140 {
  141   fprintf (stdout, "No sysinfo information available for unknown system\n");
  142   return (0);
  143 }
  144 
  145 #endif