




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































A process is a program in execution which then forms the basis of all computation. The process is not as same as program code but a lot more than it. A process is an 'active' entity as opposed to the program which is considered to be a 'passive' entity. Attributes held by the process include hardware state, memory, CPU, etc. Process memory is divided into four sections for efficient working : The Text section is made up of the compiled program code, read in from non-volatile storage when the program is launched. The Data section is made up of the global and static variables, allocated and initialized prior to executing the main. The Heap is used for the dynamic memory allocation and is managed via calls to new, delete, malloc, free, etc. The Stack is used for local variables. Space on the stack is reserved for local variables when they are declared.
Processes in the operating system can be in any of the following states: NEW- The process is being created. READY- The process is waiting to be assigned to a processor. RUNNING- Instructions are being executed. WAITING- The process is waiting for some event to occur(such as an I/O completion or reception of a signal). TERMINATED- The process has finished execution.
I/O Status information : Devices allocated, open file tables, etc.
Let us take a look at the differences between Process and Program: Process Program The process is basically an instance of the computer program that is being executed. A Program is basically a collection of instructions that mainly performs a specific task when executed by the computer. A process has a shorter A Program has a longer lifetime.
Process Program lifetime. A Process requires resources such as memory, CPU, Input-Output devices. A Program is stored by hard-disk and does not require any resources. A process has a dynamic instance of code and data A Program has static code and static data. Basically, a process is the running instance of the code. On the other hand, the program is the executable code. Process Scheduling When there are two or more runnable processes then it is decided by the Operating system which one to run first then it is referred to as Process Scheduling. A scheduler is used to make decisions by using some scheduling algorithm. Given below are the properties of a Good Scheduling Algorithm : Response time should be minimum for the users.
Pre-emptive Scheduling: When the operating system decides to favour another process, pre- empting the currently executing process.
All processes, upon entering into the system, are stored in the Job Queue. Processes in the Ready state are placed in the Ready Queue. Processes waiting for a device to become available are placed in Device Queues. There are unique device queues available for each I/O device. A new process is initially put in the Ready queue. It waits in the ready queue until it is selected for execution(or dispatched). Once the process is assigned to the CPU and is executing, one of the following several events can occur: The process could issue an I/O request, and then be placed in the I/O queue. The process could create a new subprocess and wait for its termination. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state to the ready state, and is then put back in the ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated.
There are three types of schedulers available:
Addition of Medium-term scheduling to the queueing diagram.
store all registers). Typical speeds range from 1 to 1000 microseconds.
Below we have discussed the two major operation Process Creation and Process Termination. Process Creation Through appropriate system calls, such as fork or spawn, processes may create other processes. The process which creates other process, is termed the parent of the other process, while the created sub-process is termed its child. Each process is given an integer identifier, termed as process identifier, or PID. The parent PID (PPID) is also stored for each process. On a typical UNIX systems the process scheduler is termed as sched, and is given PID 0. The first thing done by it at system start-up time is to launch init, which gives that process PID 1. Further Init launches all the system daemons and user logins, and becomes the ultimate parent of all other processes.
/* Fork another process */ pid = fork(); if(pid < 0 ) { //Error occurred fprintf(stderr, "Fork Failed"); exit(- 1 ); } else if (pid == 0 ) { //Child process execlp("/bin/ls","ls",NULL); } else { //Parent process //Parent will wait for the child to complete wait(NULL);
When a process ends, all of its system resources are freed up, open files flushed and closed, etc. The process termination status and execution times are returned to the parent if the parent is waiting for the child to terminate, or eventually returned to init if the process already became an orphan. The processes which are trying to terminate but cannot do so because their parent is not waiting for them are termed zombies. These are eventually inherited by init as orphans and killed off.
In the "First come first serve" scheduling algorithm, as the name suggests, the process which arrives first, gets executed first, or we can say that the process which requests the CPU first, gets the CPU allocated first. First Come First Serve, is just like FIFO (First in First out) Queue data structure, where the data element which is added to the queue first, is the one who leaves the queue first. This is used in Batch Systems. It's easy to understand and implement programmatically, using a Queue data structure, where a new process enters through the tail of the queue, and the scheduler selects process from the head of the queue. A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
For every scheduling algorithm, Average waiting time is a crucial parameter to judge it's performance.
AWT or Average waiting time is the average of the waiting times of the processes in the queue, waiting for the scheduler to pick them for execution. Lower the Average Waiting Time, better the scheduling algorithm. Consider the processes P1, P2, P3, P4 given in the below table, arrives for execution in the same order, with Arrival Time 0 , and given Burst Time , let's find the average waiting time using the FCFS scheduling algorithm. The average waiting time will be 18.75 ms For the above given proccesses, first P1 will be provided with the CPU resources, Hence, waiting time for P1 will be 0 P1 requires 21 ms for completion, hence waiting time for P2 will be 21 ms
This essentially leads to poort utilization of resources and hence poor performance.
Here we have a simple C++ program for processes with arrival time as 0. If you are not familiar with C++ language, we would recommend you to first Learn C++ language. In the program, we will be calculating the Average waiting time and Average turn around time for a given array of Burst times for the list of processes. /* Simple C++ program for implementation of FCFS scheduling */ #include
// waiting time for first process will be 0 wt[ 0 ] = 0 ; // calculating waiting time for (int i = 1 ; i < n ; i++) { wt[i] = bt[i- 1 ] + wt[i- 1 ]; } } // function to calculate turn around time void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[]) { // calculating turnaround time by adding // bt[i] + wt[i] for (int i = 0 ; i < n ; i++) { tat[i] = bt[i] + wt[i]; }