xref: /minix/minix/tests/test64.c (revision 83133719)
1 
2 /* Code to test reasonable response to out-of-memory condition
3  * of regular processes.
4  */
5 
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <dlfcn.h>
9 
10 #include <sys/mman.h>
11 #include <sys/wait.h>
12 
13 int max_error = 2;
14 #include "common.h"
15 
16 
17 #include "magic.h"
18 
19 int main (int argc, char *argv[])
20 {
21   pid_t f;
22   start(64);
23 #define NADDRS 500
24 #define LEN 4096
25   static void *addrs[NADDRS];
26   int i = 0;
27   int st;
28 
29   if((f=fork()) == -1) {
30   	e(1);
31 	exit(1);
32   }
33 
34   if(f == 0) {
35   	/* child: use up as much memory as we can */
36 	while((addrs[i++ % NADDRS] = mmap(0, LEN, PROT_READ|PROT_WRITE,
37 		MAP_PREALLOC|MAP_CONTIG|MAP_ANON, -1, 0)) != MAP_FAILED)
38 			;
39 	exit(0);
40   }
41 
42   /* parent: wait for child */
43   if(waitpid(f, &st, 0) < 0)
44 	perror("waitpid");
45 
46   quit();
47 
48   return(0);
49 }
50