Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.unix.questions Subject: Re: Determining system memory Message-ID: <1050@mcgill-vision.UUCP> Date: 12 Apr 88 21:20:29 GMT References: <248@lxn.UUCP> Organization: McGill University, Montreal Lines: 48 In article <248@lxn.UUCP>, chris@lxn.UUCP (Christopher D. Orr) writes: > I have been trying to find a nice, clean way to determine system > memory under SYS V 2.2. > Solution 2: [This is faster than Solution 1, but still slow]: [program] Well, you could speed it up by doing a more intelligent search technique than linear search: /****** UNTESTED (no SV system to test it on) ******/ #include #include extern int errno; static char buf; main() { long int l; long int m; long int h; int fd; fd = open("/dev/mem",O_RDONLY); /* check for fd<0 omitted for brevity */ l = 1; h = 2; while (1) { lseek(fd,h,L_SET); /* or whatever the SV way is */ if (read(fd,&buf,1) != 1) break; l = h; h *= 2; } while (h-l > 1) { m = (h + l) / 2; lseek(fd,m,L_SET); /* or whatever */ if (read(fd,&buf,1) == 1) l = m; else h = m; } printf("%ld bytes accessible via /dev/mem\n",h); exit(0); } der Mouse uucp: mouse@mcgill-vision.uucp arpa: mouse@larry.mcrcim.mcgill.edu