home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / misc / 4270 < prev    next >
Encoding:
Text File  |  1992-11-20  |  4.9 KB  |  168 lines

  1. Path: sparky!uunet!spool.mu.edu!agate!agate.berkeley.edu!dodd
  2. From: dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd)
  3. Newsgroups: comp.unix.misc
  4. Subject: Re: how much memory do i have??
  5. Followup-To: comp.unix.misc
  6. Date: 20 Nov 92 06:21:46
  7. Organization: Dept of Chemical Engineering, Polytechnic Univ, NY, USA
  8. Lines: 152
  9. Message-ID: <DODD.92Nov20062146@mycenae.cchem.berkeley.edu>
  10. References: <1992Nov18.015943.5705@sea.com> <1992Nov19.032021.5356@pvi.com>
  11.     <1992Nov20.000058.13035@megatek.com> <15578@auspex-gw.auspex.com>
  12. Reply-To: dodd@roebling.poly.edu
  13. NNTP-Posting-Host: mycenae.cchem.berkeley.edu
  14. In-reply-to: guy@Auspex.COM's message of 20 Nov 92 07:56:45 GMT
  15.  
  16.  
  17. This was posted to the net a while back.  I find it most useful.
  18.  
  19. ..............................................................
  20. /*
  21.  * From jdd@db.toronto.edu Wed Feb 12 09:45:23 1992
  22.  * Newsgroups: comp.sys.sun.admin
  23.  * From: jdd@db.toronto.edu (John DiMarco)
  24.  * Subject: Re: Boot messages, how to find out Memory
  25.  * Organization: Department of Computer Science, University of Toronto
  26.  * Date: 11 Feb 92 18:45:27 GMT
  27.  * 
  28.  * jpd@tardis.cl.msu.edu (Joe P. DeCello) writes:
  29.  * 
  30.  * >mem = 49152K (0x3000000)
  31.  * 
  32.  * >Telling me of course, that there is 48meg installed.
  33.  * >How can I find this out from a command line prompt?
  34.  * 
  35.  * Here's a little program that'll do the trick. It's short, so I'll include it
  36.  * here. Thanks to Dave Curry and Larry Breniser. I've hacked it a little.
  37.  * 
  38.  * John
  39.  * --
  40.  * John DiMarco                                              jdd@cdf.toronto.edu
  41.  * Computing Disciplines Facility Systems Manager            jdd@cdf.utoronto.ca
  42.  * University of Toronto                                     EA201B,(416)978-1928
  43.  *
  44.  * ----------- cut here -----------------
  45.  * Figure out how much memory there is on a machine.  This works under
  46.  * Berkeley UNIX.  It should work under System V if you change the
  47.  * UNIX define to "/unix" instead of "/vmunix".
  48.  *
  49.  * Of course, if you don't have read permission on the kernel and
  50.  * kernel memory, this won't work.
  51.  *
  52.  * Dave Curry
  53.  * Purdue University
  54.  * Engineering Computer Network
  55.  *
  56.  * Hacked by Larry Breniser 10/1/91
  57.  * Pagesize is now determied dynamically, not at compile
  58.  * time, as it varies from host to host (server vs workstation)
  59.  *
  60.  * davy@intrepid.ecn.purdue.edu
  61.  * $Header: /src/mem/RCS/mem.c,v 1.4 1991/12/20 00:22:53 jdd Exp $
  62.  * $Log: mem.c,v $
  63.  * Revision 1.4  1991/12/20  00:22:53  jdd
  64.  * Added a verbose option which behaves like the previous revision.
  65.  * Changed the physmem figure to report memory in KBs
  66.  * Added a usage message
  67.  * Made the non -verbose default behave like the revision before the last.
  68.  *
  69.  * Revision 1.3  1991/10/15  19:52:26  jdd
  70.  * *** empty log message ***
  71.  *
  72.  * Revision 1.2  1991/10/15  19:51:11  jdd
  73.  * New version which works on machines with different page sizes.
  74.  *
  75.  * Revision 1.3  91/10/02  17:51:10  larryb
  76.  * Added Version string to executable for ident.
  77.  *
  78.  * Revision 1.2  91/10/02  17:46:21  larryb
  79.  * Added RCS log comments.
  80.  *
  81.  */
  82. #include <sys/param.h>
  83. #include <sys/types.h>
  84. #include <nlist.h>
  85. #include <stdio.h>
  86.  
  87. char version[] = "$Header: /src/mem/RCS/mem.c,v 1.4 1991/12/20 00:22:53 jdd Exp$";
  88.  
  89. #define UNIX    "/vmunix"
  90. #define KMEM    "/dev/kmem"
  91.  
  92. struct nlist nl[] = {
  93. #define X_PHYSMEM       0
  94.         { "_physmem" },
  95. #define X_MAXMEM        1
  96.         { "_maxmem" },
  97.         { NULL }
  98. };
  99.  
  100. main(argc, argv)
  101. int argc;
  102. char **argv;
  103. {
  104.         int kmem;
  105.         int maxmem, physmem;
  106.         int pagesize;
  107.         int verbose = 0;
  108.  
  109.         if(argc>1){
  110.                 if(0==strcmp("-v", argv[1])) {
  111.                         verbose=1;
  112.                 } else {
  113.                         fprintf(stderr, "Usage: %s [-v]\n", argv[0]);
  114.                         exit(1);
  115.                 }
  116.         }
  117.  
  118.         /*
  119.          * Look up addresses of variables.
  120.          */
  121.         if ((nlist(UNIX, nl) < 0) || (nl[0].n_type == 0)) {
  122.                 fprintf(stderr, "%s: no namelist.\n", UNIX);
  123.                 exit(1);
  124.         }
  125.  
  126.         /*
  127.          * Open kernel memory.
  128.          */
  129.         if ((kmem = open(KMEM, 0)) < 0) {
  130.                 perror(KMEM);
  131.                 exit(1);
  132.         }
  133.  
  134.         /*
  135.          * Read variables.
  136.          */
  137.         lseek(kmem, (long) nl[X_PHYSMEM].n_value, 0);
  138.         read(kmem, (char *) &physmem, sizeof(int));
  139.  
  140.         lseek(kmem, (long) nl[X_MAXMEM].n_value, 0);
  141.         read(kmem, (char *) &maxmem, sizeof(int));
  142.  
  143.         close(kmem);
  144.  
  145.  
  146.         pagesize=getpagesize();
  147.  
  148.         /*
  149.          * Print the numbers.  The internal representation is
  150.          * in units of core clicks; convert to bytes.
  151.          */
  152.  
  153.         if(verbose) printf("Pagesize: %d\n", pagesize);
  154.  
  155.         if(verbose) {
  156.                 printf("Physical machine memory (KB): %d\n", (pagesize*physmem)/
  157. 1024);
  158.         } else {
  159.                 printf("%d\n", (pagesize * physmem)/1024);
  160.         }
  161.         if(verbose) printf("Max memory available to a process: %d\n", pagesize *
  162.  maxmem);
  163.  
  164.         exit(0);
  165. }
  166.  
  167.  
  168.