log-writes: Add support to output human readable flags
[xfstests-dev.git] / src / usemem.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18  
19 /*
20  *
21  * usemem: allocate and lock a chunk of memory effectively removing
22  *         it from the usable physical memory range
23  *
24  *                                                  - dxm 04/10/00
25  */
26
27 #include <stdio.h>
28 #include <malloc.h>
29 #include <sys/mman.h>
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <signal.h>
34 #include <unistd.h>
35
36 void
37 usage(char *argv0)
38 {
39     fprintf(stderr,"Usage: %s <mb>\n", argv0);
40     exit(1);
41 }
42
43 static void
44 signalled(int sig)
45 {
46     printf("*** signal\n");
47 }
48
49 int
50 main(int argc, char *argv[])
51 {
52     int mb;
53     char *buf;
54     
55     if (argc!=2) usage(argv[0]);
56     mb=atoi(argv[1]);
57     if (mb<=0) usage(argv[0]);
58     
59     buf=malloc(mb*1024*1024);
60     if (!buf) {
61         perror("malloc");
62         exit(1);
63     }
64     if (mlock(buf,mb*1024*1024)) {
65         perror("mlock");
66         exit(1);
67     }
68     
69     printf("%s: %d mb locked - interrupt to release\n", argv[0], mb);
70     signal(SIGINT, signalled);
71     pause();
72     printf("%s: %d mb unlocked\n", argv[0], mb);
73     
74     return 0;
75 }
76
77