Page 55 - DCAP103_Principle of operating system
P. 55

Principles of Operating Systems



                   Notes         of processes leaving the system. Thus, the long-term scheduler may need to be invoked only
                                 when a process leaves the system. Because of the longer interval between executions, the long-
                                 term scheduler can afford to take more time to select a process for execution.
                                 The long-term scheduler  must  make  a  careful  selection.  In  general,  most  processes  can  be
                                 described as either I/O bound or CPU bound. An 110-bound process spends more of its time
                                 doing I/O than it spends doing computations.  A CPU-bound  process,  on  the  other  hand,
                                 generates I/O requests infrequently, using more of its time doing computation than an I/O-
                                 bound process uses. The long-term scheduler should select a good process mix of I/O-bound
                                 and CPU-bound processes. If all processes are I/O bound, the ready queue will almost always
                                 be empty, and the short-term scheduler will have little to do. If all processes are CPU bound,
                                 the I/O waiting queue will almost always be empty, devices will go unused, and again the
                                 system will be unbalanced. The system with the best performance will have a combination of
                                 CPU-bound and I/O-bound processes.
                                 On  some  systems,  the  long-term  scheduler  may  be  absent  or  minimal.  For  example,  time-
                                 sharing  systems  such  as  UNIX  often  have  no  long-term  scheduler,  but  simply  put  every
                                 new process in memory for the short-term scheduler. The stability of these systems depends
                                 either  on  a  physical  limitation  (such  as  the  number  of  available  terminals)  or  on  the  self-
                                 adjusting  nature  of  human  users.  If  the  performance  declines  to  unacceptable  levels,  some
                                 users will simply quit. Some operating systems, such as time-sharing systems, may introduce
                                 an  additional,  intermediate  level  of  scheduling.  This  medium-term  scheduler,  diagrammed
                                 in  Figure  2.6,  removes  processes  from  memory  (and  from  active  contention  for  the  CPU),
                                 and  thus  reduces  the  degree  of  multiprogramming.  At  some  later  time,  the  process  can  be
                                 reintroduced into memory and its execution can be continued where it left off. This scheme is
                                 called swapping. The process is swapped out, and is later swapped in, by the medium-term
                                 scheduler. Swapping may be necessary  to  improve  the  process  mix,  or  because  a  change  in
                                 memory requirements has overcommitted available memory, requiring memory to be freed up.

                                        Figure 2.6: Addition of Medium-term Scheduling to the Queueing Diagram


                                              Swapin         Partially executed       Swap out
                                                           swapped-out processes




                                                           Ready queue              CPU                 End



                                                                             I/O waiting
                                                            I/O
                                                                              queues





                                            Give the process of PCB with all step.


                                 2.3.3 Context Switch

                                 Switching the CPU to another process requires saving the state of the old process and loading
                                 the saved state for the new process. This task is known as a context switch. The context of a
                                 process is represented in the PCB of a process; it includes the value of the CPU registers, the
                                 process state and memory-management information. When a context switch occurs, the kernel
                                 saves the context of the old process in its PCB and loads the saved context of the new process



        48                                LOVELY PROFESSIONAL UNIVERSITY
   50   51   52   53   54   55   56   57   58   59   60