Problem 1.) How is the operating system able to resume a process where it left o
ID: 3592306 • Letter: P
Question
Problem 1.) How is the operating system able to resume a process where it left off? What structures and /or tables are used?
Problem 2.) You are performing a design review of work done by a developer. In one section, he has a design that uses two semaphores to limits access to code that updates a global variable, “turn” to all but one process. Do you see any problems with his design?
Process 0 Process 1
---------- ----------
down(S); down(Q);
down(Q); down(S);
turn++; turn--;
up(S); up(Q);
up(Q); up(S);
#define N 100 int count = 0; I* number of slots in the buffer / I* number of items in the buffer / void producervoid) int item; while (TRUE) { item = produce_item( ); if (count == N) sleep(); insert_item(item); count = count + 1; if (count == 1) wakeup(consumer); (* repeat forever +/ (* generate next item */ Iif buffer is fullgo to sleep +/ I put item in buffer +/ /increment count of items in buffer */ 1+ was buffer empty? +/ void consumer(void ) int item; while (TRUE) { I repeat forever +/ if (count e=0) sleep() ; / if buffer is empty, got to sleep +/ item = remove item( ); I+ take item out of buffer +/ count = count - 1 /decrement count of items in buffer / if (count == N – 1) wakeup(producer); I x was buffer full? +/ consume_item(item); (* print item +/Explanation / Answer
Hi,
Its against chegg policy to post more than questions as one, all these are independent questions and we will be penalised if we answere more than one, so please post others as separate questions and help each other :)
Process scheduling is an integral part of the Operating System, Each process has a PCB- which is process control block, used as an identifier for that process
The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a separate queue for each of the process states and PCBs of all processes in the same execution state are placed in the same queue. When the process changes its state, its PCB is unlinked from its current queue and moved to its new state queue.
The Operating System maintains the following process scheduling queues
Job queue This queue keeps all the processes in the system.
Ready queue This queue keeps a set of all processes residing in main memory, ready and waiting to execute. A new process is always put in this queue.
Device queues The processes which are blocked due to unavailability of an I/O device constitute this queue.
The process of switching one process from another is called context switch.
A context switch is the mechanism to store and restore the state or context of a CPU in PCB so that a process execution can be resumed from the same point at a later time. Via this,a context switcher enables multiple processes to share a single CPU.
When the scheduler switches the CPU from executing one process to execute another, the state from the current running process is stored into the process control block. After this, the state for the process to run next is loaded from its own PCB and used to set the PC, registers, etc. At that point, the second process can start executing.
The OS uses different policies to manage each queue (FIFO, Round Robin etc.). The OS scheduler is responsible how to move processes between the ready and run queues which can only have single entry per processor.
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.