2961
|
1 /* Derived from the example in the OSF1 knlist manpage. |
|
2 OSF1 spe154.testdrive.compaq.com V5.0 1094 alpha |
|
3 aka (w/my private hostname compaq-tru64-50a) */ |
2960
|
4 #include <stdio.h> |
|
5 #include <string.h> |
|
6 #include <stdlib.h> |
|
7 #include <nlist.h> |
2962
|
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 |
2960
|
18 main () |
|
19 { |
2962
|
20 struct nlist nl[2]; |
|
21 int retval; |
|
22 long offset; |
2960
|
23 |
2962
|
24 nl[0].n_name = LDAV_SYMBOL; |
|
25 nl[1].n_name = ""; |
2960
|
26 |
|
27 /*******************************************************/ |
|
28 /* Call the knlist routine */ |
2962
|
29 retval = knlist (nl); |
2960
|
30 |
|
31 /******************************************************/ |
|
32 /* Display addresses if returned. Otherwise, display */ |
|
33 /* the appropriate error message. */ |
|
34 if (retval < 0) |
2962
|
35 { |
|
36 printf ("No kernel symbol addresses returned.\n"); |
|
37 exit (1); |
|
38 } |
|
39 |
|
40 if (nl[0].n_type == 0) |
|
41 { |
|
42 printf ("Unable to return address of symbol %s\n", nl[0].n_name); |
|
43 exit (1); |
|
44 } |
|
45 |
|
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); |
2960
|
70 } |