Operating Systems CSCI 330/509 Spring 2019 XXXXXXXXXX1/5 NEW YORK INSTITUTE OF TECHNOLOGY Spring 2019 Programming Assignment #2 Job Queue: adding and deleting processes Students who submit late...

1 answer below »
Need by March 5


Operating Systems CSCI 330/509 Spring 2019 1/5 NEW YORK INSTITUTE OF TECHNOLOGY Spring 2019 Programming Assignment #2 Job Queue: adding and deleting processes Students who submit late assignments will receive up to 50% credit. This is an individual assignment, not a group assignment. Students are expected to comply with NYIT’s Academic Integrity Policy and complete this assignment on their own. For this assignment please submit a single zip file. The zip file will contain: 1. Your code; 2. README pdf document with: a. clear description of your program design; b. Instructions on how to run your code; 3. Full output of your program, not just one screenshot; Your objective is to create a program that simulates several users working on a single computer system - creating and terminating processes (each process represented by PCB). Processes’ PCBs are added to and deleted from linked list that emulates job queue. You may write your program in Java, C, C++ or Python. Prerequisites: This programming assignment is designed to be built on top of previously completed programming assignments #1. In this assignment, you will simply add functionality that will delete processes from a job queue. Program Requirements/ Details: Scenario that your program should emulate: Computer system has 5 users. Randomly selected user wakes up every (randomly selected) interval 1-5 seconds - and creates a process. Meaning, user creates Process Control Block (PCB) object. Created PCBs are added to a linked list. Every second time when user wakes up, in addition to adding new process, user also deletes one random process from a queue. In other words, your previously completed first assignment implemented following functionality: … - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; Operating Systems CSCI 330/509 Spring 2019 2/5 - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; - … Result of your current assignment should work like this: … - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - User deletes one randomly selected process from job queue; - System sleeps for 1-5 seconds; - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - System sleeps for 1-5 seconds; - - Random user wakes up; - User creates new process and adds PCB to a linked list (job queue); - User deletes one randomly selected process from job queue; - System sleeps for 1-5 seconds; - … Here is what your program should accomplish: Every 1 to 5 seconds random user wakes up and creates one PCB object (process) described above. You should add newly created PCB to a linked list, which will emulate computer’s job queue. (should be already accomplished in first assignment) Every second time when user wakes up, in addition to creating one process, user also deletes one randomly selected process from a job queue. Meaning, user’s rate of creating processes is two times faster than process termination rate. Every 20 seconds you should show job queue report indicating (see sample output at the end of this document): 1. How many processes every user currently owns; 2. Current total number of jobs in a queue; 3. Number of processes created since last report; 4. Number of processes terminated since last report; Operating Systems CSCI 330/509 Spring 2019 3/5 5. Last created PID; For this assignment, limit total number of created jobs to 40. At the end, you should print full current status of your job queue. Meaning – all details of every PCB present in a queue. There should be less than 40 processes in job queue - as certain number of them were terminated. Suggestions / Considerations: 1. Study Chapter “Processes” and get familiar with the concepts of PCB and Job Queue. 2. If you want, you can create/code singly linked list on your own, manually, from the scratch. However, it is completely acceptable if you utilize existing linked list class (such as LinkedList in Java); 3. Next programming assignments for this semester will be build on top of this one. 4. Specifics and particulars of your output (graphics or character-based, specific format and visual layout) are entirely up to you – the only requirement here is: produced output should clearly show that program goals and requirements are accomplished. Sample output attached below, it is only an example to help illustrate program’s functionality; Sample output: run: Users starting to create processes.. updates every 20 seconds ===> Sat Jan 05 17:06:18 PST 2019 ============== PROCESSES QUEUE SUMMARY ============= ---------------------------------------------------- Total number of processes currently in queue : 0 Last created Process ID : 0 Number of processes created since last report : 0 Number of processes terminated since last report: 0 ---------------------------------------------------- ===> Sat Jan 05 17:06:41 PST 2019 ============== PROCESSES QUEUE SUMMARY ============= User2: 2 processes User5: 2 processes User3: 1 processes ---------------------------------------------------- Total number of processes currently in queue : 5 Last created Process ID : 9 Number of processes created since last report : 9 Number of processes terminated since last report: 4 ---------------------------------------------------- ===> Sat Jan 05 17:07:01 PST 2019 ============== PROCESSES QUEUE SUMMARY ============= User2: 2 processes User5: 3 processes User4: 2 processes User1: 1 processes ---------------------------------------------------- Total number of processes currently in queue : 8 Last created Process ID : 16 Number of processes created since last report : 7 Number of processes terminated since last report: 4 ---------------------------------------------------- Operating Systems CSCI 330/509 Spring 2019 4/5 ===> Sat Jan 05 17:07:25 PST 2019 ============== PROCESSES QUEUE SUMMARY ============= User2: 4 processes User4: 2 processes User5: 2 processes User1: 3 processes User3: 2 processes ---------------------------------------------------- Total number of processes currently in queue : 13 Last created Process ID
Answered Same DayMar 04, 2021

Answer To: Operating Systems CSCI 330/509 Spring 2019 XXXXXXXXXX1/5 NEW YORK INSTITUTE OF TECHNOLOGY Spring...

Ximi answered on Mar 06 2021
135 Votes
job_queue_1.py
import random, time
class PCB:
"""
Process control Block
"""
def __init__(self, pid, user):
"""
Constructor
"""
self.pid = pid
self.user = user
self.state = "RUNNING"
self.memory_size = random.randint(20972, 41943)
self.start_time = time.asctime()

def stop(self):
"""
Change state to stop
"""
self.state = "STOPPED"
class Computer:
"""
Class computer to emulate queue
"""
queue = []
def __init__(self):
"""
Constructor
"""
print ("Computer Queue")

@staticmethod
def add(pcb):
"""
Adds job to the queue
"""
Computer.queue.append(pcb)
class UserCommunity:
def __init__(self, name):
self.name = name
self.processes = 0

def create_process(self, pid):
process = PCB(pid, self.name)
Computer.add(process)
self.processes += 1
#Creating Five Users
users = [UserCommunity("User %d"%i) for i in range(1,6)]
if __name__ == '__main__':
    last_report = 0
    while len(Computer.queue) < 40:
     print ("===> {}".format(time.asctime()))
     print ("============== PROCESSES QUEUE SUMMARY =============")
    
     __processes_users =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here