Stxxl  1.4.0
utils/mlock.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  utils/mlock.cpp
00003  *
00004  *  Allocate some memory and mlock() it to consume physical memory.
00005  *  Needs to run as root to block more than 64 KiB in default settings.
00006  *
00007  *  Part of the STXXL. See http://stxxl.sourceforge.net
00008  *
00009  *  Copyright (C) 2010 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00010  *
00011  *  Distributed under the Boost Software License, Version 1.0.
00012  *  (See accompanying file LICENSE_1_0.txt or copy at
00013  *  http://www.boost.org/LICENSE_1_0.txt)
00014  **************************************************************************/
00015 
00016 #include <cstdlib>
00017 #include <cstring>
00018 #include <iostream>
00019 #include <sys/mman.h>
00020 #include <unistd.h>
00021 
00022 int main(int argc, char ** argv)
00023 {
00024     if (argc == 2) {
00025         long M = atol(argv[1]);
00026         if (M > 0) {
00027             char * c = (char *)malloc(M);
00028             for (long i = 0; i < M; ++i)
00029                 c[i] = 42;
00030             if (mlock(c, M) == 0) {
00031                 std::cout << "mlock(, " << M << ") successful, press Ctrl-C to finish" << std::endl;
00032                 while (1)
00033                     sleep(86400);
00034             } else {
00035                 std::cerr << "mlock(, " << M << ") failed!" << std::endl;
00036                 return 1;
00037             }
00038         }
00039     } else {
00040         std::cout << "Usage: " << argv[0] << " <bytes>" << std::endl;
00041     }
00042 }
00043 
00044 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines