Technical Point.

The Best Platform of Diploma CSE Students.

Subscribe Us

Breaking

Friday, July 31, 2020

PROCESSES unit 2.


PROCESSES

Process

Process is a program in execution. It is the unit of work in most system.
It should reside in the main memory
It is occupied the CPU to execute the instructions.
A process is basically a program in execution. The execution of a process must progress in a sequential fashion.
A process is defined as an entity which represents the basic unit of work to be implemented in the system.
The execution of a process must programs in a sequential manner. At any time at most one instruction is executed. The process includes the current activity as represented by the value of the program counter and the content of the processors registers. Also it includes the process stack which contain temporary data (such as method parameters return address and local variables) & a data section which contain global variables.

The Process Concept: -

A process is an instance of a program in execution.
Batch systems work in terms of "jobs". Many modern process concepts are still expressed in terms of jobs, ( e.g. job scheduling ), and the two terms are often used interchangeably
A process is an instance of a program in execution. Basically, a process is not the same ass “program”.12398
       1)  A program is a passive text of executable codes resides in disk.
       2)  Process is a basically a programming execution.
       3)  The execution of a process must process in sequential fashion.
       4)  A process is an active entity ready for execution which includes; a program counter, stack and data section.
        5)  When a task is loaded into the memory, it becomes a process.
                   

                                      Figure 3.1 - A process in memory


Stack :- The process stack contains the temporary data such as method ,function ,parameters return address and local variable
HEAP :- This is dynamically allocated memory to a process during its run time
TEXT :- This include the current activity represented by the value of program counter and the contents of the processing register
DATA:- This section contains the global and static variable

System Program View and Process
A program is pieces of code which may be a single line or millions of lines . A computer program is usually written by a computer programmer in a programming language.
For Ex-
#include
#include
void main()
{
Printf(“ Technical Point “);
Getch();
}
A program is collection of instruction that performing a special task when executed by a computer , we can conclude instance of a computer program 

Process control block: (PCB):-

    A process in an OS is represented by a data structure known as process Control Block (PCB) or process desperiptor .
A PCB keeps all the information needed to keep track of a process . The architecture of PCB is completely depended on operating system and may control different information in different OS

Each process is represented in the OS by a process control block. It is also by a process control block. It is also known as task control block.
A process control block contains many pieces of information associated with a specific process.

PCB contains the following information
Process state: The state may be new, ready, running, waiting or terminated state.
Program counter:- it indicates the address of the next instruction to be executed for this purpose.

CPU registers:- The registers vary in number & type depending on the computer architecture. It includes accumulators, index registers, stack pointer & general purpose registers, plus any condition- code information must be saved when an interrupt occurs to allow the process to be continued correctly after- ward.

• CPU scheduling information:- This information includes process priority pointers to scheduling queues & any other scheduling parameters.

Memory management information: This information may include such information as the value of the bar & limit registers, the page tables or the segment tables, depending upon the memory system used by the operating system.

Accounting information: This information includes the amount of CPU and real time used, time limits, account number, job or process numbers and so on. 

• I/O Status Information: This information includes the list of I/O devices allocated to this process, a list of open files and so on. The PCB simply serves as the repository for any information that may vary from process to process.

Process State
Process Number
Program counter
Register
Memory limits
List of open files
.......






                             








Fig: Process Control Block

  v     Attributes /Context of Process:
1.    Process ID
2.    Process State
3.    Program Counter
4.    Priority
5.    General purpose registers
6.    List of open files
7.    List of open device
8.    Protection information etc

1    .    Process ID :- Process Id is the unique identification number given by operating system to process of time of process creation.
Unique identification for each of the process in the operating system.

2   .    Process State :- Process state is the current activity of that process. In which particular state process is currently residing
Eg- New , Ready , Run

3   .    Program Counter :- PC contains the address next instruction to be executed
4   .    Priority :- Priority is parameter which is assigned by OS to the process
5   .    General Purpose Register :-what kind of register the process is using that register information is maintained in general purpose register

Note :- Context of process will be stored in process control block (PCB) each process has its own PCB will be implemented using double linked list

Note :- PCB of process will be started in main memory




A process may be in one of the following states :-


§  NEW :- Initial the process is in the new state , it means the process is under creation or the process is being created

§  READY STATE :- Once the process is created it moves to the ready state in the ready state there will be multiple number of process and one of the process will be selected and that will be dispatched on to the remaining state

§  RUN TIME :- In the running state there will be only one process at any point of time . In the running state the process will perform CPU time and it is executing instructions on the CPU.

§  WAIT OR BLOCK  :- In the wait state there will be multiple number of process .It means multiple process will perform input operation parallel

§  Terminated:- The process has finished execution.

§  SUSPENDED READY :- When the ready queue becomes full , Some processes are moved to suspended ready state

§  SUSPENDED BLOCK :-When waiting queue becomes full.

Multiprogramming OS  :-
None pre-emptive :-  Running process will not get disturb forcefully
Pre-Emptive /Multitasking /time sharing :-   Forcefully interrupting or disturbing the process

Note:- When the Process is in the ready state , running state and wait state block it is in the main memory
Note :- If the resources are not sufficient to manage the process in the ready state then process in the ready state then sum of the process will be suspended and they will be moved on to suspend ready state .
Note :- When the process in suspend ready state .it is in the secondary memory when resources available process from suspend ready state move back to ready state .

DEGREE OF MULTIPROGRAMMING:-
Number of process present in main memory at any point of time is called degree of multiprogramming
DISPATCHER:- Responsibility of dispatcher is loaded a process from ready state to run state . It is also responsible for performing context switching .
 DISPATCHER LATENCY: - Time taken to start one process and stop another process.
CPU BOUND PROCESS :- The process which required more amount of CPU are called CPU bound . These processes will spend more time in running state
I/O BOUND PROCESS:- The process which required more amount of i/o time are called i/o bound processes . This processes will spend more time in wait state .
CONTEXT SWITCHING:  Each and every time when the process is moving from one state to another state the context ( attributes ) of the process will change .

DEFINITION OF CONTEXT  SWITCHING  :-
Saving the context of process and loading the context of other process is called Context Switching
The Context switching time is considered as the overload for the system.
Similarly, a context switch occurs when the time slice for one process has expired and a new process is to be loaded from the ready queue. This will be instigated by a timer interrupt, which will then cause the current process's state to be saved and the new process's state to be restored.
Context switching happens VERY VERY frequently, and the overhead of doing the switching is just lost CPU time, so context switches ( state saves & restores ) need to be as fast as possible. Some hardware has special provisions for speeding this up, such as a single machine instruction for saving or restoring all registers at once.

Note :- In some special cases if there is only one process then still it is considered as context switching .
Eg- Round Robin scheduler algorithm
Schedulers :-
Schedulers are special system software which handle process scheduling in various way . Their main task is to select the job to be submitted into system and to decide which program run .

Scheduler are three types:-
1    .      Long Term scheduler
2   .     Short Term Scheduler
3   .     Medium Term Scheduler

  v     LTS (Long Term Scheduler ) :

LTS is responsible for creating new process and beginning them into system. LTS select process from job pool (where process are kept run later execution ) and load them into memory for execution . LTS control degree of Multiprogramming.

Job scheduler/ Long term scheduler is responsible for creating and bringing the new process into the system.
It is also called job scheduler. It selects processes from the pool and loads them into memory for execution

Long term scheduler selects process from the disk & loads them into
memory for execution. It controls the degree of multi-programming i.e. no. of processes in memory. It executes less frequently than other schedulers. If the degree of multiprogramming is stable than the average rate of process creation is equal to the average departure rate of processes leaving the system. So, the long term scheduler is needed to be invoked only when a process leaves the system. Due to longer intervals between executions
it can afford to take more time to decide which process should be selected for execution. Most processes in the CPU are either I/O bound or CPU bound. An I/O bound process (an interactive ‘C’ program is one that spends most of its time in I/O operation than it spends in doing I/O operation. A CPU bound process is one that spends more of its time in
doing computations than I/O operations (complex sorting program). It is important that the long term scheduler should select a good mix of I/O bound & CPU bound processes. 

  v     STS  / CPU SCHEDULER :-

STS is responsible for selecting one of the process in the ready state for scheduling on to running state or CPU. It is also called CPU scheduler

The short term scheduler selects among the  process that are ready
to execute & allocates the CPU to one of them. The primary distinction between these two schedulers is the frequency of their execution. The short-term scheduler must select a new process for the CPU quite frequently. It must execute at least one in 100ms. Due to the
short duration of time between executions, it must be very fast.
The short-term scheduler, or CPU Scheduler, runs very frequently, on the order of 100 milliseconds, and must very quickly swap one process out of the CPU and swap in another one.


  v MTS/SWAPPER :-

MTS is responsible for suspending and resuming the process the job done by MTS is called as Swapping.

some operating systems introduce an additional intermediate
level of scheduling known as medium - term scheduler. The main idea behind this scheduler is that sometimes it is advantageous to remove processes from memory & thus reduce the degree of multiprogramming. At some later time, the process can be reintroduced into memory & its execution can be continued from where it had left off. This is called as
swapping. The process is swapped out & swapped in later by medium term scheduler. Swapping is necessary to improve the process miss or due to some change in memory requirements, the available memory limit is exceeded which requires some memory to be freed up.
Some systems also employ a medium-term scheduler. When system loads get high, this scheduler will swap one or more processes out of the ready queue system for a few seconds, in order to allow smaller faster jobs to finish up quickly and clear the system

Ø  Dispatcher :-
·       The dispatcher is responsible of performing the context switching .the Dispatcher is also responsible of loading the selected job on to the CPU
·       Selecting of job is done by STS & loading by dispatcher
·       The LTS should select the good combination of both CPU bound and i/o bound process in order to get good throughput for the system
·       If LTS selects only CPU bound time then CPU utilization increase but throughput decrease if LTS selects only i/o bound time then CPU idleness increase.



Note :- LTS should select the good combination of both CPU bound and I/O bound process in order to get good throughput for the system.
                                                                             
Note:- LTS controls degree of multiprogramming

Q.  consider a system which has n CPU processors then what is the min & the max no. of processes that may present in the ready, running & block


min
max
Ready
0
Running
0
n
Wait/block
0


  •  SCHEDULING ALGORITHM :-

Scheduling algorithm are used distributing resources among processes which simultaneously and asynchronous request them
 A process scheduler different process to be a sign to the CPU based on particular scheduling algorithm . It is the primitive and a other process executed for a given time period.
Schedu
ling deals with the problem of deciding which of the requests is to be allocated resources.
CPU Scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated first to the CPU. There are four types of CPU scheduling that exist
There are many different scheduling algorithms they are as follows:
    I.          FCFS (First Come First Serve)
 II.          SJN or  SJF (Shortest Job Nest / First)
III.          Round Robin Scheduling
IV.          Shortest Test Remaining Time
  V.            Priority Scheduling
VI.          Multi Level Queues Scheduling

  v AT (Arrival Time ) :- The time when the process is arrived into the ready state
  v BT (Burst Time ):- The time required by process to complete its execution
  v CT (Completion Time ) :- The time when the process is completed its total execution is                                                          called CT
  v TAT (Turn Around Time) :- The time difference between the CT and AT is called TAT                                                                  (TAT=CT-AT)
  v WT (Waiting Time ) :-  The difference between TAT and BT is time called as WT of the                                                      process (WT=TAT-BT)
  v RT (Response Time ) :- The time difference between first response and the AT

Note :- STS is responsible for schedule scheduling .

Goals of CPU Scheduling :-
       1.     To maximize CPU utilization & throughput of the system
       2.    To minimize the average TAT, Avg. WT & Avg. RT of the processes 

FIRST COME FIRST SERVE (FCFS)

First Come, First Served Scheduling (FCFS) Algorithm:- This is the simplest CPU scheduling algorithm. In this scheme, the process which requests the CPU first, that is allocated to the CPU first. The implementation of the FCFS algorithm is easily managed with a FIFO queue. When a process enters the ready queue its PCB is linked onto the rear of the queue
First Come First Serve is the scheduling of processes where the process leaves the queue in the order in which they arrive.
It is based on Queuing.
The FCFS scheduling algorithm in non-preemptive.

Criteria :- Arrival Time (AT)
Mode :- None pre-emptive algorithm

Q. Find out the avg.TAT & Avg. WT.
P.NO
AT
BT
CT
TAT
WT
P1
0
3
3
3
0
P2
1
1
4
3
2
P3
2
4
8
6
2
P4
3
5
13
10
5
P5
4
2
15
11
9
Total number of process = 5
33
18










Gantt chart  
P1
P2
P3
P4
P5
0                     3                         4                            8                       13                  15     
Sum of TAT = 33
Sum of WT =18
AVG. TAT =33/5=6.6
AVG. WT =18/5=3.6

NOTE: - if the Arrival time (AT) of the process are matching then schedule the process which has lowest process ID.

Q. Find out the avg.TAT & Avg. WT.
P.NO
AT
BT
CT
TAT
WT
p1
6
3
29
23
20
P2
3
8
18
15
7
p3
4
4
22
18
14
p4
2
6
10
8
2
p5
1
3
4
3
0
p6
5
4
26
21
17
Total number of process = 6
+88
+60

Gantt chart                   
CPU idle
P5
P4
P2
P3
P6
P1
0           1                4          10             18           11           26       29
Sum of TAT = +88
Sum of WT = +60
AVG. TAT = 88/6=14.6
AVG. WT = 60/6=10



Q. Find out the avg.TAT & Avg. WT.
P.NO
AT
BT
CT
TAT
WT
P1
12
8
21
9
1
P2
9
4
13
4
0
P3
3
3
6
3
0
P4
2
1
3
1
0
P5
3
2
8
5
3
P6
15
9
30
15
6
Total number of process = 6
+37
+10

Gantt chart 
CPU idle
P4
P3
P5
CPU idle
P2
P1
P5
0                2               3                 6                3                9                13              21        30
Sum of TAT =  +37
Sum of WT = +10
AVG. TAT = 37/6 = 6.16
AVG. WT = 10/6= 1.66

Convey Effect –
In the FCFS If the process is having large BT (CPU bound) then it will have the major effect on avg. WT of the process. This effect is called as Convey effect.
Ex--
Q. Find out the avg.TAT & Avg. WT.
P.NO
AT
BT
CT
TAT
WT
P1
0
20
20
20
0
P2
1
2
22
21
19
P3
2
2
24
22
20
Total number of process = 3
+63
+39

Gantt chart 
P1
P2
P3
  0                           20                             22                             24
Sum of TAT = 63
Sum of WT = 39
AVG. TAT =  63/3=21                                 AVG. WT = 39/3=13

Q. Find out the avg.TAT & Avg. WT.
P.NO
AT
BT
CT
TAT
WT
P1
0
2
2
2
0
P2
1
2
4
3
2
P3
2
20
24
22
1
Total number of process = 3
+28
+3
Gantt chart 
P1
P2
P3
  0                            2                              4                               24
Sum of TAT = 28
Sum of WT = 3
AVG. TAT =  28/3= 9.33                            AVG. WT = 3/3=1

SHORTEST JOB FIRST (SJF)

Shortest Job First Scheduling (SJF) Algorithm:- This algorithm associates with each process if the CPU is available. This scheduling is also known as shortest next CPU burst, because the scheduling is done by examining the length of the next CPU burst of the process rather than its total length
Shortest Job First, which connects with each process the length of second next CPU bursts
Whichever process requires less time to complete the execution is processed first
        If there is a case, where two processes in ready queue has same CPU burst, FCFS is used to decide among them.
          This algorithm takes minimum average waiting time.
           To schemes to find the shortest job first : -
a.           Non-pre-emptive: - once CPU given to the process it cannot be pre-empted until completes its CPU bursts.
b.          Pre-emptive: - if a new process arrives with CPU burst length less than remaining time of current executing process, pre-empt. This scheme is known as the Shortest-Remaining Time-First (SRTF).

Criteria :- Burst Time (BT)
Mode:-  1. Non- pre-emptive              2. Pre-emptive

       1.    Non- pre-emptive:-

Q. Find out the avg.TAT & Avg. WT

P.NO
AT
BT
CT
TAT
WT
P1
1
7
8
7
0
P2
2
5
16
14
9
P3
3
1
9
6
5
P4
4
2
11
7
5
        P5      
5
8
24
19
11
Total number of process = 5
+53
+30

Gantt chart
CPU idle
P1
P3
P4
P2
P5


0              1                 8                  9                 11                16            24
Sum of TAT =  53
Sum of WT = 30
AVG. TAT = 53/5=10.6
AVG. WT = 30/5=6

·       Note :- if the BT of the processes are matching then schedule the process which has lowest AT.



Q. Find out the avg.TAT & Avg. WT
P.NO
AT
BT
CT
TAT
WT
P1
6
1
8
2
1
P2
3
3
13
10
7
P3
4
6
19
15
9
P4
1
5
6
5
0
P5
2
2
10
8
6
P6
5
1
7
2
1
Total number of process = 6
+42
+24

Gantt chart 
CPU idle
P4
P6
P1
P5
P2
P3
   0               1                 6                7                  8                   10               13              19                              
Sum of TAT =  42
Sum of WT = 24
AVG. TAT = 42/6=7
AVG. WT = 24/6=4

Q. Find out the avg.TAT & Avg. WT
P.NO
AT
BT
CT
TAT
WT
P1
0
2
2
2
0
P2
1
3
5
11
1
P3
2
5
14
12
07
P4
3
4
09
06
02
P5
4
6
20
16
10
Total number of process = 5
+40
+20

Gantt chart 
P1
P2
P4
P3
P5
  0                   2                         5                       9                         14                    20
Sum of TAT =  40
Sum of WT = 20
AVG. TAT = 40/5=8
AVG. WT = 20/5=4

SHORTEST JOB FIRST / SHORTEST REMAINING TIME FIRST (SRTF) PRE -EMTIVE .

Criteria: - Burst Time (BT)
Mode:-   Pre-emptive.

Q. Find out the avg.TAT & Avg. WT
P.NO
AT
BT
CT
TAT
WT
P1
0
7  4 5
14
14
7
P2
1
6
20
19
13
P3
2
3  2  1  0
6
4
1
P4
3
1   0
4
1
0
P5
4
2   1   0
9
5
3
P6
5
1    0
7
2
1
Total number of process = 6
+45
+25

Gantt chart
P1
P1
P3
P4
P3
P3
P6
P5
P1
P2
  0            1               2             3               4              5               6               7            9               14         20
Sum of TAT =  45
Sum of WT = 25
AVG. TAT = 45/6 = 7.5
AVG. WT = 25/6=4.16

Q. Find out the avg.TAT & Avg. WT
P.NO
AT
BT
CT
TAT
WT
P1
3
4
13
10
6
P2
4
2  1    0
9
5
3
P3
5
1    0
7
2
1
P4
2
6
19
17
11
P5
1
8    7
26
25
17
P6
2
4   3   2   1   0
6
4
0
Total number of process = 6
+63
+38

Gantt chart
CPU idle
P5
P6
P6
P6
P6
P3
P2
P2
P1
P4
P5
 0           1           2           3            4           5           6             7            8          9           13           19     26      
Sum of TAT = 63
Sum of WT = 38
AVG. TAT = 63/6=10.5
AVG. WT = 38/6=6.3

Priority Scheduling
The priority will be assigned t each of the process . The higher the priority the sooner will the process get the CPU .If the priority of the two process is some then they will be schedule according to their arrival time.
In this scheduling a priority is associated with each process and the CPU is allocated to the process with the highest priority. Equal priority processes are scheduled in FCFS manner
Priority is associated with each process in the queue and the process with the highest priority is processed.  SJF is an example of priority algorithm.

Criteria :- Priority
Mode :- 1. Non-pre-emptive
               2. pre-emptive

Note :- If the priority of the process are matching then schedule the process which has lower AT

1. Non-pre-emptive:-

Q. Find out the avg.TAT & Avg. WT
Priority
P.NO
AT
BT
CT
TAT
WT
4
P1
0
4
4
4
0
5
P2
1
5
16
15
10
Highest 7
P3
2
1
5
3
2
2
P4
3
2
18
15
13
Lowest- 1
P5
4
3
21
17
14
6
P6
5
6
11
6
0
Total number of process = 6
+60
+39

    Gantt chart
P1
P3
P6
P2
P4
P5
       0                    4                     5                    11                     16                    18                21
Sum of TAT = 60
Sum of WT = 39
AVG. TAT = 60/6=10
AVG. WT = 39/6= 6.5



Q. Find out the avg.TAT & Avg. WT
Priority
P.NO
AT
BT
CT
TAT
WT
4
P1
4
6
17
13
7
5
P2
6
3
11
5
2
6
P3
3
4
8
5
1
6
P4
2
2
4
2
0
High  7
P5
1
1
2
1
0
Low  3
P6
2
2
19
17
2
Total number of process = 6
+43
+25

Gantt chart
CPU idle
P5
P4
P3
P2
P1
P6
  0                1                    2                   4                   8                  11                  17           19
Sum of TAT = 43
Sum of WT = 25
AVG. TAT =  43/6=7.1
AVG. WT = 25/6=4.1
  

PRE-EMPTIVE

Q. Find out the avg.TAT & Avg. WT
Priority
P.NO
AT
BT
CT
TAT
WT
Low  4
P1
1
4   1
18
17
17
5
P2
2
2
14
12
10
7
P3
2
3   2   0
10
8
5
High 8
P4
3
5    0
8
5
0
5
P5
3
1
15
12
11
6
P6
4
2
12
8
6
Total number of process = 6
+62
+45

Gantt chart
CPU idle
P1
P3
P4
P3
P6
P2
P5
P1
 0                1            2               3              8             10             12             14             15      18

Sum of TAT =  62
Sum of WT = 45
AVG. TAT =  62/6=10.33
AVG. WT = 45/6=7.5

Q. Find out the avg.TAT & Avg. WT
Priority
P.NO
AT
BT
CT
TAT
WT
5
P1
1
4   3   2
16
15
11
2
P2
2
5
21
19
14
6
P3
3
6    5
14
11
5
4
P4
0
1    0
1
1
0
7
P5
4
2     1
9
5
3
8
P6
5
3
8
3
0
Total number of process = 6
54
33



Gantt chart
P4
P1
P1
P3
P5
P6
P5
P3
P1
P2
  0         1              2             3             4             5            8            9           14            16      21
Sum of TAT =  54
Sum of WT = 33
AVG. TAT =  54/6=9
AVG. WT = 33/6=5.5

Round Robin Scheduling

Round Robin Scheduling Algorithm: This type of algorithm is designed only for the time sharing system. It is similar to FCFS scheduling with preemption condition to switch between processes. A small unit of time called quantum time or time slice is used to switch between the processes. The average waiting time under the round robin policy is quiet long.

It is especially used with time sharing systems. It is called as process sharing approach.

The queue is seen as a circular queue.

 The queue is kept as FIFO queue.

As the time quantum is completed the queue is dispatched
Criteria :- AT & TQ (TIME QUANTUM) (or) Time Slice
Mode :- pre-emptive
TIME QUANTUM (TQ) :- Whenever  the  process is scheduled for execution the Maximum Time the process will execute at that time

Note :- Round Robin Scheduling algorithm is implemented using  circular queue

Note:- If Arrival time of the process are not given in the question then by default consider it as Zero.

Note:- In the Round Robin if TQ is very- very  large then the Round Robin Algorithm behaves like FCFS OR FIFO Scheduling .

 Note :- In Round Robin if TQ is less then number of context switches will in increase and response time will be less

Note:- If TQ is large then numbers of context switches will be less and response time will be more


Q. Find out the avg.TAT & Avg. WT & Avg. RT

TQ=2
P.NO
AT
BT
CT
TAT
WT
RT
P1
0
4   2    0
8
8
4
0
P2
1
5  3   1   0
18
17
12
1
P3
2
2    0
6
4
2
2
P4
3
1
9
6
5
5
P5
4
6     4    2
21
17
11
5
P6
6
3     1    0
19
13
10
7
Total number of process = 6
65
44
20

RQ (Ready Queue ) (in which order the process will come)
RQ=   P1    P2  P3        P1        P4        P5        P2        P6        P5        P2        P6        P5

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

Avg. TAT = 65/6=10.8
Avg. WT = 44/6                                                            Avg. RT= 20/6= 3.33 (RT= first response-AT)

Q. Find out the avg.TAT & Avg. WT & Avg. RT
TQ= 3
P.NO
AT
BT
CT
TAT
WT
 RT
P1
5
5
32
27
22
10
P2
4
6
27
23
17
5
P3
3
7
33
30
23
3
P4
1
9
30
29
20
0
P5
2
2
6
4
2
2
P6
6
3
21
15
12
12
Total number of process = 6
128
96
32

READY QUEUE :-  P4  P5        P3        P2        P4        P1        P6        P3        P2        P4        P1            P3
Gantt chart
CPU idle
P4
P5
P3
P2
P4
P1
P6
P3
P2
P4
P1
P3
  0           1           4            6           9          12          15          18          21          24         27          30         32     33
Avg. RT = 32/6=5.3
Avg. WT= 96/6=12
Avg. TAT = 128//6= 21.3

     Operating System Services for Process Management: -
      1. Process management is integral part of any model operating system.
       

        
    An operating system provides an environment for the execution of the program. Following are the various services provided by an operating system: -
  • Program Execution: The operating system must provide the ability to load a program into memory at run time.
  • I/O Operation: Program in running process must require I/O. It may involve in a file or specific I/O device.
  • File System Manipulation: The operating system must provide the capability to read, write, create and delete a file for user program. Therefore each and every files must maintained correctly by the operating system.
   • Communication: The process of sharing message via shared memory or by the technique of message passing in which packets of information are moved between the processes by the operating system this process is called communication.
   • Error detection: Operations like arithmetic overflow, access to the illegal memory location and too large user CPU time, the operating system should take the appropriate actions for these occurrences.
   • Research Allocation: It is the ability to allocate multiple users, which are logged on to the system the resources must be allocated to each of them. Among the various processes the operating system uses the CPU scheduling algorithms which determine which process will be allocated with the resource.
   • Accounting: Operating system keep track of the users which use how many and which kind of computer resources.
• Protection: The protection of hardware as well as software is the responsibility of operating system.

SYSTEM CALL :- System call is the request made by user program to OS i order to get any kind of service 
Eg- printf-write() monitor
Printf internally calls write system call in order to get interact with keyboard

The Fork():


        1.      System Call fork() is used to create process . it take no arguments and returns a process ID
        2.      The purpose of fork() is to create a new process, which becomes child process of the caller .     
        3.      After a new child process is created, both processes will executed the nest instruction following the fork()          system call,
        4.      Therefore we have  to distinguish the parent from the child .

This can be done by testing the return value of fork()
·        If Fork() return a negative value , the creation of child process was unsuccessful .
·        If fork() return a  Zero to the newly created child process
·        If fork() return a positive value , the process ID of the child process to the parent . Normally the process ID is an integer moreover, a  process can use function getpid() to retrieve the process ID assigned to this process
Conclusion :-
·        If the program contains n fork() calls it will create 2n-1 child process
·        When the child process is created by using fork system call . both parent and child will have
·        Relative address = same for both parent and child process
·        Absolute Address = different for both parent and child process
Fork() system call implemented –
            Main()
{
Int pid;
Pid=fork();
If(pid<0 o:p="">
{
Printf(“child process creation failed “);
Else if(pid==0)
{
Printf(“child process”);
}
Else
{
Printf(“parent process” )
}
}

No comments:

Post a Comment

Recently

All C program

Write a C program to print ‘Hello World’ on screen . #include < stdio.h > #include < conio.h > void  m...