Mercurial > gnulib
comparison lib/tru-knlist-demo.c @ 2962:08a841b1a567
*** empty log message ***
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sun, 05 Nov 2000 10:12:25 +0000 |
parents | 6f34939d48af |
children |
comparison
equal
deleted
inserted
replaced
2961:6f34939d48af | 2962:08a841b1a567 |
---|---|
3 aka (w/my private hostname compaq-tru64-50a) */ | 3 aka (w/my private hostname compaq-tru64-50a) */ |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <nlist.h> | 7 #include <nlist.h> |
8 | |
9 #ifndef FD_CLOEXEC | |
10 # define FD_CLOEXEC 1 | |
11 #endif | |
12 | |
13 #ifndef LDAV_SYMBOL | |
14 # define LDAV_SYMBOL "_avenrun" | |
15 #endif | |
16 | |
17 int | |
8 main () | 18 main () |
9 { | 19 { |
10 struct nlist nl[3]; | 20 struct nlist nl[2]; |
11 int retval, i; | 21 int retval; |
12 nl[0].n_name = (char *)malloc(10); | 22 long offset; |
13 nl[1].n_name = (char *)malloc(10); | |
14 nl[2].n_name = ""; | |
15 | 23 |
16 /*******************************************************/ | 24 nl[0].n_name = LDAV_SYMBOL; |
17 /* Store names of kernel symbols in the nl array */ | 25 nl[1].n_name = ""; |
18 strcpy (nl[0].n_name, "ncpus"); | |
19 strcpy (nl[1].n_name, "lockmode"); | |
20 | 26 |
21 /*******************************************************/ | 27 /*******************************************************/ |
22 /* Call the knlist routine */ | 28 /* Call the knlist routine */ |
23 retval = knlist(nl); | 29 retval = knlist (nl); |
24 | 30 |
25 /******************************************************/ | 31 /******************************************************/ |
26 /* Display addresses if returned. Otherwise, display */ | 32 /* Display addresses if returned. Otherwise, display */ |
27 /* the appropriate error message. */ | 33 /* the appropriate error message. */ |
28 if (retval < 0) | 34 if (retval < 0) |
29 printf ("No kernel symbol addresses returned.\n"); | 35 { |
30 else | 36 printf ("No kernel symbol addresses returned.\n"); |
31 if (retval >= 0 ) | 37 exit (1); |
32 for (i=0; i<2; i++) | 38 } |
33 if (nl[i].n_type == 0) | 39 |
34 printf ("Unable to return address of symbol %s\n", | 40 if (nl[0].n_type == 0) |
35 nl[i].n_name); | 41 { |
36 else | 42 printf ("Unable to return address of symbol %s\n", nl[0].n_name); |
37 printf ("The address of symbol %s is %lx\n", | 43 exit (1); |
38 nl[i].n_name, nl[i].n_value); | 44 } |
39 free (nl[0].n_name); | 45 |
40 free (nl[1].n_name); | 46 offset = nl[0].n_value; |
47 printf ("The address of symbol %s is %lx\n", nl[0].n_name, offset); | |
48 | |
49 { | |
50 double load_ave[3]; | |
51 int channel = open ("/dev/kmem", 0); | |
52 if (channel < 0) | |
53 { | |
54 printf ("open failed\n"); | |
55 exit (1); | |
56 } | |
57 #ifdef FD_SETFD | |
58 (void) fcntl (channel, F_SETFD, FD_CLOEXEC); | |
59 #endif | |
60 | |
61 if (lseek (channel, offset, 0) == -1L | |
62 || read (channel, (char *) load_ave, sizeof (load_ave)) | |
63 != sizeof (load_ave)) | |
64 { | |
65 close (channel); | |
66 } | |
67 } | |
68 | |
69 exit (0); | |
41 } | 70 } |