memcg_test_4.c revision 354ebb48db8e66a853a58379a4808d5dcd1ceac3
1/******************************************************************************/ 2/* */ 3/* Copyright (c) 2009 FUJITSU LIMITED */ 4/* */ 5/* This program is free software; you can redistribute it and/or modify */ 6/* it under the terms of the GNU General Public License as published by */ 7/* the Free Software Foundation; either version 2 of the License, or */ 8/* (at your option) any later version. */ 9/* */ 10/* This program is distributed in the hope that it will be useful, */ 11/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ 13/* the GNU General Public License for more details. */ 14/* */ 15/* You should have received a copy of the GNU General Public License */ 16/* along with this program; if not, write to the Free Software */ 17/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ 18/* */ 19/* Author: Li Zefan <lizf@cn.fujitsu.com> */ 20/* */ 21/******************************************************************************/ 22 23#include <sys/mman.h> 24#include <err.h> 25#include <signal.h> 26#include <stdio.h> 27#include <stdlib.h> 28#include <string.h> 29#include <unistd.h> 30#include <unistd.h> 31 32#define MEM_SIZE (1024 * 1024 * 100) 33 34void sigusr_handler(int __attribute__ ((unused)) signo) 35{ 36 char *p; 37 38 p = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, 39 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 40 if (p == MAP_FAILED) { 41 err(1, "failed to allocate memory!"); 42 } 43 44 memset(p, 'z', MEM_SIZE); 45} 46 47int main(void) 48{ 49 struct sigaction sigusr_action; 50 51 memset(&sigusr_action, 0, sizeof(sigusr_action)); 52 sigusr_action.sa_handler = &sigusr_handler; 53 sigaction(SIGUSR1, &sigusr_action, NULL); 54 55 while (1) 56 sleep(1); 57 58 return 0; 59} 60