sbin/hammer2/cmd_snapshot.c: Fix error handling
[dragonfly.git] / test / stress / eatmem.c
blob2671bc2a7aef4d7599d0f3efb2e30ebc3d81a18b
1 /*
2 * EATMEM.C
4 * (c)Copyright 2003 Matthew Dillon <dillon@backplane.com>. This code is
5 * hereby placed in the public domain.
7 * This program 'eats' memory by allocating and touching it. Make sure your
8 * datasize resource limit is sufficient for the amount of memory you specify.
10 * $DragonFly: src/test/stress/eatmem.c,v 1.1 2003/08/25 19:41:00 dillon Exp $
12 #include <sys/types.h>
13 #include <sys/mman.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
19 int
20 main(int ac, char **av)
22 size_t bytes;
23 size_t i;
24 char *ptr;
26 if (ac == 1) {
27 printf("eatmem MB [msec/page]\n");
28 printf("specifying msec/page will cause eatmem to loop forever\n");
29 exit(1);
31 bytes = strtoul(av[1], NULL, 0) * 1024 * 1024;
32 ptr = malloc(bytes);
34 for (;;) {
35 for (i = 0; i < bytes; i += 4096) {
36 ++ptr[i];
37 if (av[2] && strtol(av[2], NULL, 0))
38 usleep(1000 * strtol(av[2], NULL, 0));
39 if (i == 0)
40 puts("loop0");
42 if (ac != 3)
43 break;
44 puts("loop");
46 puts("ok");
47 sleep(10);
48 puts("done");
49 exit(0);