-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cpp
37 lines (31 loc) · 974 Bytes
/
driver.cpp
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
#include <iostream>
#include <dirent.h>
#include "utility/buffer_cache.hpp"
#include "utility/process.hpp"
int main() {
// Initializing a Buffer Cache object with free list of size 2
// and an empty buffer pool
buffer_cache cache(2);
// Counts number of opened terminals, and accordingly assigns
// 'pid' to a particular process later on
DIR *dp = opendir("/dev/pts/");
int i = 0;
if (dp != nullptr) {
while (readdir(dp)) {
i++;
}
closedir(dp);
} else {
std::cerr << "Couldn't open the Directory" << std::endl;
}
// Generates processes, using std::thread
std::thread t1(process, &cache, i - 3);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::thread t2(process, &cache, i - 2);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::thread t3(process, &cache, i - 1);
t1.join();
t2.join();
t3.join();
return 0;
}