-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsstest.c
55 lines (49 loc) · 1.46 KB
/
rsstest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/eventfd.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <unistd.h>
void dump(int pid) {
char cmd[1000];
sprintf(cmd,
"grep '^VmRSS' /proc/%d/status;"
"grep '^Rss:' /proc/%d/smaps_rollup;"
"echo",
pid, pid);
system(cmd);
}
int main(void) {
eventfd_t dummy;
int child_wait = eventfd(0, EFD_SEMAPHORE | EFD_CLOEXEC);
int child_resume = eventfd(0, EFD_SEMAPHORE | EFD_CLOEXEC);
if (child_wait == -1 || child_resume == -1) err(1, "eventfd");
pid_t child = fork();
if (child == -1) err(1, "fork");
if (child == 0) {
if (prctl(PR_SET_PDEATHSIG, SIGKILL)) err(1, "PDEATHSIG");
if (getppid() == 1) exit(0);
char *mapping = mmap(NULL, 80 * 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
eventfd_write(child_wait, 1);
eventfd_read(child_resume, &dummy);
for (int i = 0; i < 40; i++) mapping[0x1000 * i] = 1;
eventfd_write(child_wait, 1);
eventfd_read(child_resume, &dummy);
for (int i = 40; i < 80; i++) mapping[0x1000 * i] = 1;
eventfd_write(child_wait, 1);
eventfd_read(child_resume, &dummy);
exit(0);
}
eventfd_read(child_wait, &dummy);
dump(child);
eventfd_write(child_resume, 1);
eventfd_read(child_wait, &dummy);
dump(child);
eventfd_write(child_resume, 1);
eventfd_read(child_wait, &dummy);
dump(child);
eventfd_write(child_resume, 1);
exit(0);
}