xref: /dragonfly/test/stress/t_mlockall.c (revision 8f2ce533)
1 #include <err.h>
2 #include <stdlib.h>
3 #include <sys/mman.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6 #include <unistd.h>
7 
8 #define TESTSIZE	(32*1024*1024L)
9 
10 char *TestBuf;
11 
12 void
13 child(void)
14 {
15 	size_t i;
16 
17         sleep(1);
18 	for (i = 0; i < TESTSIZE; i += 4096) {
19 		++TestBuf[i];
20 		//usleep(1000000 / 10);
21 	}
22 	usleep(1000000 / 4);	/* ensure children are concurrent */
23 }
24 
25 int
26 main(int argc, char **argv)
27 {
28         int status;
29 
30 	TestBuf = malloc(TESTSIZE);
31 
32         if (fork() == 0) {
33 		if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
34 			err(1, "mlockall(MCL_CURRENT | MCL_FUTURE)");
35 		fork();
36                 child();
37 		exit(0);
38 	}
39         wait(&status);
40 
41         return (0);
42 }
43