Page 59 - DCAP403_Operating System
P. 59

Operating System




                    Notes          a single process a few hundred microseconds of CPU time before replacing it with another
                                   process.)
                                   Some of these resources (such as memory) are simultaneously shared by all processes. Such
                                   resources are being used in parallel between all running processes on the system. Other resources
                                   must be used by one process at a time, so must be carefully managed so that all processes get
                                   access to the resource. Such resources are being used in concurrently between all running
                                   processes on the system.
                                   The most important example of a shared resource is the CPU, although most of the I/O devices
                                   are also shared. For many of these shared resources the operating system distributes the time a
                                   process requires of the resource to ensure reasonable access for all processes. Consider the CPU:
                                   the operating system has a clock which sets an alarm every few hundred microseconds. At this
                                   time the operating system stops the CPU, saves all the relevant information that is needed to
                                   re-start the CPU exactly where it last left off (this will include saving the current instruction being
                                   executed, the state of the memory in the CPUs registers, and other data), and removes the process
                                   from the use of the CPU.
                                   The operating system then selects another process to run, returns the state of the CPU to what it
                                   was when it last ran this new process, and starts the CPU again. Let’s take a moment to see how
                                   the operating system manages this.

                                   The processes in the system can execute concurrently, and they must be created and deleted
                                   dynamically. Thus, the operating system must provide a mechanism (or facility) for process
                                   creation and termination.
                                   4.3.1 Processes Creation


                                   The creation of a process requires the following steps. The order in which they are carried out is
                                   not necessarily the same in all cases.
                                   1.   Name: The name of the program which is to run as the new process must be known.

                                   2.   Process ID and Process Control Block: The system creates a new process control block,
                                       or locates an unused block in an array. This block is used to follow the execution of the
                                       program through its course, keeping track of its resources and priority. Each process
                                       control block is labeled by its PID or process identifi er.
                                   3.   Locate the program to be executed on disk and allocate memory for the code segment in
                                       RAM.
                                   4.   Load the program into the code segment and initialize the registers of the PCB with the
                                       start address of the program and appropriate starting values for resources.

                                   5.   Priority: A priority must be computed for the process, using a default for the type of

                                       process and any value which the user specified as a `nice’ value.
                                   6.   Schedule the process for execution.

                                   Process Hierarchy: Children and Parent Processes

                                   In a democratic system anyone can choose to start a new process, but it is never users which
                                   create processes but other processes! That is because anyone using the system must already be
                                   running a shell or command interpreter in order to be able to talk to the system, and the command
                                   interpreter is itself a process.
                                   When a user creates a process using the command interpreter, the new process becomes a child
                                   of the command interpreter. Similarly the command interpreter process becomes the parent for
                                   the child. Processes therefore form a hierarchy.



          52                               LOVELY PROFESSIONAL UNIVERSITY
   54   55   56   57   58   59   60   61   62   63   64