Professional Documents
Culture Documents
OS-minproject 20BCE1835
OS-minproject 20BCE1835
Students submit print jobs to be handled by shared printers at VIT printing facility. The
operating system is in charge of controlling the print queue and making sure that every
student has an equal opportunity to print their Digital Assignments. The intention is to put in
place a simulator that shows how resource management and job scheduling are done in the
printing facility.
> Defining a class to represent each user with attributes like user ID and submitted print
jobs.
> Defining a class to represent each printer with attributes like printer ID, status (idle or
busy), and the current print job.
Print Queue:
>Simulating the job scheduling system where users submit print jobs, and the operating
system manages the print queue.
Code:
#include <iostream>
#include <vector>
#include <queue>
#include <thread>
#include <mutex>
//User representation
class User {
public:
int userID;
vector<string> printJobs;
//Printer representation
class Printer {
public:
int printerID;
bool isBusy;
string currentJob;
Printer(int printerID) : printerID(printerID), isBusy(false), currentJob("") {}
};
queue<string> printQueue;
mutex printMutex;
unique_lock<mutex> lock(printMutex);
if (!printQueue.empty()) {
string job = printQueue.front();
printQueue.pop();
cout << "Printer " << printer.printerID << " finished printing: " << job << endl;
printer.isBusy = false;
printer.currentJob = "";
}
lock.unlock();
}
}
int main() {
printQueue.push(job);
printerThread1.join();
printerThread2.join();
return 0;
}
Output: