home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / bsd / 4742 < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.3 KB  |  80 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!maverick.ksu.ksu.edu!news
  2. From: brtmac@maverick.ksu.ksu.edu (Brett McCoy)
  3. Newsgroups: comp.unix.bsd
  4. Subject: vmmeter and vmtotal structures
  5. Message-ID: <17grefINN3qt@maverick.ksu.ksu.edu>
  6. Date: 26 Aug 92 21:01:03 GMT
  7. Organization: Kansas State University
  8. Lines: 69
  9. NNTP-Posting-Host: maverick.ksu.ksu.edu
  10.  
  11. I've been trying to make a program that is similar to vmstat under
  12. SunOS for 386BSD.  However, it appears that the _sum and _total
  13. structures in the kernel are not being used.  All I get are 0's for
  14. all the values in them.  The following program should read the _sum
  15. and _total structures (struct vmmeter and struct vmtotal,
  16. respectively), from the kernel address space.  The hostname read is
  17. just there as a test to make sure that I could actually read something
  18. from kernel memory.  It works successfully.  You have to run this
  19. under gdb if you want to actually see what it reads from the kernel
  20. (who needs printf's anyway).  Am I doing something terribly wrong?
  21. I've done stuff like this with SunOS 4.x and haven't had any problems.
  22. If these structures aren't being used, are there any plans to add
  23. that ability to the kernel?  If not I may tackle it myself, but I
  24. don't want to reinvent the wheel.
  25.  
  26. ++Brett;
  27.  
  28. compile this with 'gcc -g -o vmstat vmstat.c -lutil'
  29.  
  30. --- cut here ---
  31. #include <sys/vmmeter.h>
  32. #include <stdio.h>
  33. #include <nlist.h>
  34.  
  35. extern int errno;
  36. extern char* sys_errlist[];
  37.  
  38. struct nlist nl[] = {
  39.     {"_sum"},
  40. #define NL_SUM        0
  41.     {"_total"},
  42. #define NL_TOTAL    1
  43.     {"_hostnamelen"},
  44.     {"_hostname"},
  45.     {""}
  46. };
  47.  
  48. main(int argc, char** argv)
  49. {
  50.     struct vmmeter sum;
  51.     int sum_offset;
  52.     struct vmtotal total;
  53.     int total_offset;
  54.     int len;
  55.     char name[50];
  56.  
  57.     if (kvm_openfiles(NULL, NULL, NULL) == -1) {
  58.     perror("kvm_openfiles");
  59.     return -1;
  60.     }
  61.  
  62.     if ((len = kvm_nlist(&nl)) != 0) {
  63.     fprintf(stderr, "Problem with kvm_nlist.\n");
  64.     return -1;
  65.     }
  66.     kvm_read(nl[2].n_value, &len, sizeof(sum));
  67.     kvm_read(nl[3].n_value, &name, len);
  68.  
  69.     if ((len = kvm_read(nl[NL_SUM].n_value, &sum, sizeof(sum))) <= 0) {
  70.     fprintf(stderr, "Problem reading sum.\n");
  71.     return -1;
  72.     }
  73.     if ((len = kvm_read(nl[NL_TOTAL].n_value, &total, sizeof(total))) <= 0) {
  74.     fprintf(stderr, "Problem reading total.\n");
  75.     return -1;
  76.     }
  77.  
  78.     kvm_close();
  79. }
  80.