-
Notifications
You must be signed in to change notification settings - Fork 0
/
swaptest.c
74 lines (71 loc) · 1.92 KB
/
swaptest.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "types.h"
#include "user.h"
int main(int argc,char** argv)
{
int pid;
printf(1,"\n**************** PART 1 *****************\n\n");
printf(1,"Enabling swapping now...\n");
enableSwapping();
if((pid = fork())==0)
{
pid = getpid();
printf(1,"Child process Pid = %d has %d memory pages allocated, going to sleep and will be swapped out\n",pid,getAllocatedPages(pid));
sleep2();
printf(1,"Child process pid = %d has woken up and was swapped in - has %d memory pages allocated.\n",pid,getAllocatedPages(pid));
exit();
}
else
{
int j,k;
for(j=0;j<10000000;j++)
{
k = j;
j = j+1;
j = k;
}
if(fork()==0)
{
printf(1,"we will now run the 'ls' command and see that the %d.swap file is created\n",pid);
exec("ls",argv);
}
else
{
for(j=0;j<10000000;j++)
{
k = j;
j = j+1;
j = k;
}
printf(1,"\nChild process Pid = %d is sleeping and swapped out - has %d memory pages allocated.\n",pid,getAllocatedPages(pid));
wakeup2();
while(wait()>0);
printf(1,"\n\n**************** PART 2 *****************\n\n");
printf(1,"Disabling swapping now...\n");
disableSwapping();
if((pid = fork())==0)
{
pid = getpid();
printf(1,"Child process Pid = %d has %d memory pages allocated, going to sleep and WILL NOT be swapped out\n",pid,getAllocatedPages(pid));
sleep2();
printf(1,"Child process pid = %d has woken up and was swapped in - has %d memory pages allocated.\n",pid,getAllocatedPages(pid));
exit();
}
else
{
if(fork()==0)
{
printf(1,"we will now run the 'ls' command and see that the %d.swap file has not been created\n",pid);
exec("ls",argv);
}
else
{
sleep(100);
printf(1,"\nChild process Pid = %d is sleeping and NOT swapped out - has %d memory pages allocated.\n",pid,getAllocatedPages(pid));
wakeup2();
}
}
}
}
while(wait()>0);
exit();
}