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 <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <fcntl.h>
27#include <sys/mman.h>
28#include <sys/wait.h>
29
30#define MAP_FLAGS		(MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED)
31
32#define LOOP			40
33
34#define FORKED_PROC_COUNT	10
35
36int main(void)
37{
38	char buf[10];
39	int i;
40	int loop;
41	int pid;
42	int size = getpagesize();
43	int fd = open("memcg/0/tasks", O_WRONLY);
44
45	if (fd < 0)
46		return 1;
47
48	for (loop = 0; loop < LOOP; loop++) {
49		for (i = 0; i < FORKED_PROC_COUNT; i++) {
50			pid = fork();
51			if (pid == 0) {
52				char *p;
53
54				sprintf(buf, "%d", getpid());
55				write(fd, buf, 10);
56				fsync(fd);
57
58				p = mmap(NULL, size, PROT_READ | PROT_WRITE,
59					 MAP_FLAGS, 0, 0);
60
61				if (p == MAP_FAILED) {
62					perror("mmap failed");
63					exit(1);
64				} else
65					exit(0);
66			}
67		}
68
69		for (i = 0; i < FORKED_PROC_COUNT; i++)
70			wait(NULL);
71	}
72
73	close(fd);
74
75	return 0;
76}
77