Date: Wed, 11 Dec 96 10:35:59 CST From: Joe Greco <jgreco@solaria.sol.net> To: current@freebsd.org, dyson@freebsd.org Subject: mlocking an mmap'ped region? Message-ID: <199612111636.KAA03706@solaria.sol.net>
next in thread | raw e-mail | index | archive | help
The following does not seem to work on a 2.2-CURRENT box (built yesterday). It does seem to work on SunOS. Is it just too early to be doing programming or is there really something preventing me from doing this? Thanks, ... JG #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <sys/types.h> #include <sys/mman.h> #include <sys/stat.h> /* * mlock-files - read a list of files on stdin, mmap() them, mlock() them, * and then sleep forever. */ int mapper(fd) int fd; { struct stat sb; size_t size; caddr_t map; if (fstat(fd, &sb) < 0) { perror("fstat"); close(fd); return(-1); } size = (size_t)sb.st_size; if ((int)(map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)) == -1) { perror("mmap"); close(fd); return(-1); } if (mlock(map, size) < 0) { perror("mlock"); fprintf(stderr, "map = %08x eof=%d\n", map, size); close(fd); return(-1); } else { fprintf(stderr, "allocated map = %08x eof=%d\n", map, size); } close(fd); return(0); } int main(int argc, char *argv[]) { int fd; char buffer[8192]; if (argc != 1) { fprintf(stderr, "usage: mlock-files\n"); exit(1); } while (! feof(stdin)) { fgets(buffer, sizeof(buffer), stdin); if (strchr(buffer, '\n')) { *strchr(buffer, '\n') = '\0'; } if (! feof(stdin)) { if ((fd = open(buffer, O_RDONLY, 0755)) < 0) { perror(buffer); } else { mapper(fd); } } } sleep(99999999); } -- ... Joe ------------------------------------------------------------------------------- Joe Greco - Systems Administrator jgreco@ns.sol.net Solaria Public Access UNIX - Milwaukee, WI 414/342-4847
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612111636.KAA03706>