In: Computer Science
Could you include little explanation.
What is a system call to replace the process image? If successful, what is its effect on the process that calls it?
When scheduling processes, provide an example of how round-robin which is known as one of the fairer systems, can be unfair on a multi-user system.
What is the difference between a semaphore and mutex? When would you use one over the other?
1. The exec() family of functions replaces the current process image with a new process image. It loads the program into the current process space and runs it from the entry point.This act is also referred to as an overlay.As a new process is not created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program.
A successful overlay destroys the previous memory address space of the process, and all its memory areas, that were not shared, are reclaimed by the operating system. Consequently, all its data that were not passed to the new program, or otherwise saved, become lost.
A successful exec replaces the current process image, so it cannot return anything to the program that made the call i.e. the exec system calls do not return to the invoking program as the calling image is lost. Processes do have an exit status, but that value is collected by the parent process.
If an exec function does return to the calling program, an error occurs, the return value is −1, and errno is set to one of the following values:
E2BIG-The argument list exceeds the system limit.
EACCES-The specified file has a locking or sharing violation.
ENOENT-The file or path name not found.
ENOMEM-Not enough memory is available to execute the new process image.
2. The round-robin (RR) scheduling algorithm is similar to FCFS scheduling, but preemption is added to enable the system to switch between processes.A small unit of time, called a time quantum or time slice, is defined. A time quantum is generally from 10 to 100 milliseconds in length. The ready queue is treated as a circular queue. The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum.To implement RR scheduling, we again treat the ready queue as a FIFO queue of processes. New processes are added to the tail of the ready queue.The CPU scheduler picks the first process from the ready queue, sets a timer to interrupt after 1 time quantum, and dispatches the process.
Let us consider an example of a multi user system where round robin is implemented.There are 6 processes with id, burst time and arrival time as shown below –
PID | ARRIVAL TIME | BURST TIME |
P1 | 0 | 4 |
P2 | 1 | 5 |
P3 | 2 | 2 |
P4 | 3 | 1 |
P5 | 4 | 6 |
P6 | 6 | 3 |
We consider a time quantum of 2 units and calculate average waiting
time, completion time, turn around time for each processes’s
execution.The arrival times are different as this is a multi user
system and process can arrive at any time from any user.
The execution can be represented as the following Gantt Chart.
P1 | P2 | P3 | P1 | P4 | P5 | P2 | P6 | P5 | P2 | P6 | P5 |
0 2 4 6 8 9 11 13 15 17 18 19 21
At the arrival time = 0, CPU scheduler picks up the p1 process
from the ready queue and it will run per 2 unit of time according
to given time quantum. At arrival time = 2, there are 3 processes
available P1, P2 & P3. Executed process will be placed at the
tail of the ready queue. Scheduler will select the next process
from the ready queue. So, P2 will execute first. After the
execution of P2 process, P3 will be the next the process in the
queue. So, P3 will complete execution.
According to the context switch every executed process will be
placed at the tail of the ready queue and get a chance for
execution again according to each position.
Every process will follow the same procedure. It is good practice
to make a separate queue and place the process executed process at
the tail of the queue. So, it will be easy to understand the next
process which is going to be executed.
Completion time:
P1 = 8,
P2 = 18,
P3 = 6,
P4 = 9,
P5 = 21,
P6 = 19
Turn Around time:
P1 = 8 – 0 = 8,
P2 = 18 -1 = 17,
P3 = 6 – 2 = 4,
P4 = 9 – 3 = 6,
P5 = 21 – 4 = 17,
P6 = 19 – 6 = 13
Waiting time:
P1 = 8 – 4 = 4,
P2 = 17 – 5 = 12,
P3 = 4 – 2 = 2,
P4 = 6 – 1 = 5,
P5 = 17 – 6 = 11
Here we see that since on a multi user system processes can arrive at any time therefore the following may occur making the scheduling process unfair :
3. The Key Differences Between Semaphore and Mutex are as follows:
From above we conclude that Semaphore is a better option when there are multiple instances of resources available. In the case of single shared resource mutex is a better choice.