-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-proc_dump.c
54 lines (44 loc) · 1.05 KB
/
test-proc_dump.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
/*
an user program for testing proc_dump system call
*/
#include "types.h"
#include "stat.h"
#include "user.h"
int main(int argc, char const *argv[])
{
printf(1, "user program for testing proc_dump with pid = %d\n", getpid());
if(argc != 2)
{
printf(2, "proc_dump only accepts one argument!\n");
exit();
}
int n = atoi(argv[1]);
proc_info proc_infos[n];
for (int i = 0; i < n; i++)
{
proc_infos[i].pid = 0;
proc_infos[i].memsize = 0;
}
int cpids[2];
if(!(cpids[0] = fork()))
{
//child 1
while(1);
exit();
}
if(!(cpids[1] = fork()))
{
//child 2
while(1);
exit();
}
printf(1, "child 1 with pid %d and child 2 with pid %d\n", cpids[0], cpids[1]);
malloc(2000);
proc_dump(proc_infos, n);
printf(1, "output of proc_dump(sorted by memsize):\n");
for (int i = 0; i < n; i++)
{
printf(1, "p[%d].pid = %d, p[%d].memsize = %d\n", i, proc_infos[i].pid, i, proc_infos[i].memsize);
}
exit();
}