home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!maverick.ksu.ksu.edu!news
- From: brtmac@maverick.ksu.ksu.edu (Brett McCoy)
- Newsgroups: comp.unix.bsd
- Subject: vmmeter and vmtotal structures
- Message-ID: <17grefINN3qt@maverick.ksu.ksu.edu>
- Date: 26 Aug 92 21:01:03 GMT
- Organization: Kansas State University
- Lines: 69
- NNTP-Posting-Host: maverick.ksu.ksu.edu
-
- I've been trying to make a program that is similar to vmstat under
- SunOS for 386BSD. However, it appears that the _sum and _total
- structures in the kernel are not being used. All I get are 0's for
- all the values in them. The following program should read the _sum
- and _total structures (struct vmmeter and struct vmtotal,
- respectively), from the kernel address space. The hostname read is
- just there as a test to make sure that I could actually read something
- from kernel memory. It works successfully. You have to run this
- under gdb if you want to actually see what it reads from the kernel
- (who needs printf's anyway). Am I doing something terribly wrong?
- I've done stuff like this with SunOS 4.x and haven't had any problems.
- If these structures aren't being used, are there any plans to add
- that ability to the kernel? If not I may tackle it myself, but I
- don't want to reinvent the wheel.
-
- ++Brett;
-
- compile this with 'gcc -g -o vmstat vmstat.c -lutil'
-
- --- cut here ---
- #include <sys/vmmeter.h>
- #include <stdio.h>
- #include <nlist.h>
-
- extern int errno;
- extern char* sys_errlist[];
-
- struct nlist nl[] = {
- {"_sum"},
- #define NL_SUM 0
- {"_total"},
- #define NL_TOTAL 1
- {"_hostnamelen"},
- {"_hostname"},
- {""}
- };
-
- main(int argc, char** argv)
- {
- struct vmmeter sum;
- int sum_offset;
- struct vmtotal total;
- int total_offset;
- int len;
- char name[50];
-
- if (kvm_openfiles(NULL, NULL, NULL) == -1) {
- perror("kvm_openfiles");
- return -1;
- }
-
- if ((len = kvm_nlist(&nl)) != 0) {
- fprintf(stderr, "Problem with kvm_nlist.\n");
- return -1;
- }
- kvm_read(nl[2].n_value, &len, sizeof(sum));
- kvm_read(nl[3].n_value, &name, len);
-
- if ((len = kvm_read(nl[NL_SUM].n_value, &sum, sizeof(sum))) <= 0) {
- fprintf(stderr, "Problem reading sum.\n");
- return -1;
- }
- if ((len = kvm_read(nl[NL_TOTAL].n_value, &total, sizeof(total))) <= 0) {
- fprintf(stderr, "Problem reading total.\n");
- return -1;
- }
-
- kvm_close();
- }
-