-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment1.cpp
More file actions
34 lines (29 loc) · 1.03 KB
/
assignment1.cpp
File metadata and controls
34 lines (29 loc) · 1.03 KB
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
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#include <cstdlib>
#include <cmath>
void userMemoryAllocation (int array[], int startAddress, int pages) {
int randomNum;
int numPages = 0, processSize, unusedMem;
int processID = 0;
printf("Process: Starting Mem: Size of the Process: Unused Space: \n");
for (int i = 0; i < pages; i+=numPages){
randomNum = rand() % 31;
processSize = randomNum*80; //size of the process
numPages = ceil((double)processSize/160); //number of pages for process
if(i + numPages > pages)
break;
unusedMem = (numPages*160) - processSize; //Unused space
printf("%-12d %-18d %-25d %d\n", processID, startAddress, processSize, unusedMem);
startAddress += numPages*160; //starting address of the next process
processID++;
}
}
int main (){
int array [100];
userMemoryAllocation(array, 2000, 100);
}