• No results found

Operating Systems Management 52 

In document computer fundamentals (Page 52-66)

Learning Objectives

After completing this session, you will be able to: ‰ Analyze different OS components

‰ Describe Process, Process states and Process Control Blocks ‰ Explain the different Scheduling Algorithms

Operating System Components

The operating system provides an abstraction of the computer’s resources to simplify the

programmer’s job of creating application programs. An operating system provides the environment within which programs are executed. To construct such an environment, the system is partitioned into small modules with a well-defined interface. Every OS can be created module by module. Each and every module has its own input, output and functions and all OS need not have the same structure. Many modern operating systems share the same goal of supporting the following system components.

Process Management

The operating system is responsible for the following activities in connection with processes managed.

‰ The creation and deletion of both user and system processes ‰ The suspension or resumption of processes.

‰ The provision of mechanisms for process synchronization ‰ The provision of mechanisms for process communication ‰ The provision of mechanisms for deadlock handling.

Main Memory Management

Primary memory or main memory is a large array of words or bytes. Each word or byte has its own address. Main memory provides storage that can be accessed directly by the CPU. It means that for a program to be executed, it must be in the main memory. The major activities of an operating system in regard to memory management are:

‰ Keep track of which part of memory are currently being used and by which user’s process.

‰ Decide which processes are loaded into memory when memory space becomes available.

‰ Allocate and de-allocate memory space as needed

A file is a collection of related information defined by its creator. Computer can store files on the disk (secondary storage), which provide long-term storage. Some examples of storage media are magnetic tape, magnetic disk and optical disk. Each of these media has its own properties like speed, capacity, data transfer rate and access methods. A file system is normally organized into directories to ease their use. The directories may contain files and other subdirectories. The five major activities of an operating system in regard to file management are:

‰ The creation and deletion of files ‰ The creation and deletion of directories

‰ The support of primitives for manipulating files and directories ‰ The mapping of files onto secondary storage

‰ The backup of files on stable storage media

Input /Output System Management

I/O subsystem hides the peculiarities of specific hardware devices from the user. Only the device driver knows the peculiarities of the specific device to which it is assigned.

Secondary Storage Management:

Generally, systems have several levels of storage, including primary storage, secondary storage and cache storage. Instructions and data must be placed in primary storage or cache to be referenced by a running program. Because main memory is too small to accommodate all data and programs, and its data are lost when power is lost, the computer system must provide

secondary storage to backup main memory. Secondary storage consists of tapes, disks and other media to hold information that will eventually be accessed in primary storage (primary, secondary, cache) is ordinarily divided into bytes or words consisting of a fixed number of bytes. Each location in storage has an address; this set of all addresses available to a program is called an address space. The three major activities of an operating system in regards to secondary storage management are:

‰ Managing the free space available on the secondary storage device ‰ Allocation of storage space when new files have to be written ‰ Scheduling the requests for memory access

Networking

A distributed system is a collection of processors that do not share memory, peripheral devices or a clock. The processors communicate with one another through communication lines called network. The communication-network design must consider routing and connection strategies and the problems of contention and security.

Protection System

If a computer system has multiple users and allows the concurrent execution of multiple

processes, then the various processes must be protected from one another’s activities. Protection refers to mechanism for controlling the access of programs, processes, or users of the resources defined by a computer system.

Processes and Process management

A process is the basic computational element in a modern computer system, and process management refers to the full spectrum of OS services to support the orderly administration of a collection of processes. A detailed consideration of the process management is the natural place to begin the study of OS details.

A process is a program in execution. In this module we shall explain how a process comes into existence and how processes are managed. A process in execution needs resources like processing resource, memory and IO resources. Current machines allow several processes to share resources. In reality, one processor is shared amongst many processes. A system like a file server may even support processes from multiple users. And yet the owner of every process gets an illusion that the server (read processor) is available to their process without any interruption. This requires clever management and allocation of the processor as a resource. In this module we shall study the basic processor sharing mechanism amongst processes.

What is a Process?

As we know a process is a program in execution. To understand the importance of this definition, let’s imagine that we have written a program called my_prog.c in C. On execution, this program may read in some data and output some data. Note that when a program is written and a file is prepared, it is still a script. It has no dynamics of its own i.e., it cannot cause any input processing or output to happen. Once we compile, and still later when we run this program, the intended operations take place. In other words, a program is a text script with no dynamic behavior. When a program is in execution, the script is acted upon. It can result in engaging a processor for some processing and it can also engage in I/O operations. It is for this reason a process is differentiated from program. While the program is a text script, a program in execution is a process.

In other words, To begin with let us define what a “process” is and in which way a process differs from a program. A process is an executable entity – it’s a program in execution. When we compile a C language program we get an a.out file which is an executable file. When we seek to run this file – we see the program in execution. Every process has its instruction sequence. Clearly, therefore, at any point in time there is a current instruction in execution.

A program counter determines helps to identify the next instruction in the sequence. So process must have an inherent program counter. Referring back to the C language program – it’s a text file. A program by it self is a passive entity and has no dynamic behavior of its own till we create the corresponding process. On the other hand, a process has a dynamic behavior and is an active entity. Processes get created, may have to be suspended awaiting an event like completing a certain I/O. A process terminates when the task it is defined for is completed. During the life time of a process it may seek memory dynamically. In fact, the malloc instruction in C precisely does that. In any case, from the stand point of OS a process should be memory resident and, therefore, needs to be stored in specific area within the main memory. Processes during their life time may also seek to use I/O devices. For instance, an output may have to appear on a monitor or a printed output may be needed. In other words, process management requires not only making the

processor available for execution but, in addition, allocates main memory, files and IO. The process management component then requires coordination with the main memory management, secondary memory management, as well as, files and I/O.

Process States

The process state consist of everything necessary to resume the process execution if it is somehow put aside temporarily. The process state or context of a process consists of at least following:

‰ Code for the program. ‰ Program's static data. ‰ Program's dynamic data. ‰ Program's procedure call stack. ‰ Contents of general purpose register. ‰ Contents of program counter (PC) ‰ Contents of program status word (PSW). ‰ Operating Systems resource in use.

Five state model

The five states of a process are as follows

‰ New State: The process being created.

‰ Ready State: A process is said to be ready if it use a CPU if one were available. A

ready state process is runnable but temporarily stopped running to let another process run.

‰ Blocked (or waiting) State: A process is said to be blocked if it is waiting for some

event to happen such that as an I/O completion before it can proceed. Note that a process is unable to run until some external event happens.

‰ Running State: A process is said to be running if it has the CPU, that is, process

actually using the CPU at that particular instant.

‰ Exit state: The process has finished execution.

The state transition diagram is shown in figure 4.1

Fig. 4.1: Five State Model

Process blocks for an event, appears when a process discovers that it cannot continue. In order to get into blocked state, some systems must execute a system call block. In other systems, when a process reads from a pipe or special file and there is no input available, the process is

Dispatcher picks either the same or another process for execution. Scheduler picks another process, when the scheduler decides that the running process has run long enough, and it is time to let another process have some CPU time. Scheduler picks the same process when all other processes have had their share and it is time for the first process to run again.

Process moves from blocked to ready when the external event for which it was waiting happens. If no other process is running at that instant, same process will start running. Otherwise it may have to wait in ready state for a little while until the CPU is available.

Another state is included into this five state model is called suspended state. This state says about whether process is there in the main memory or not. This is included to increase the

multiprogramming level. When the process is blocked it can be suspended till it get the event complete.

Using the process model, it becomes easier to think about what is going on inside the system. There are many processes like user processes, disk processes, terminal processes, and so on, which may be blocked when they are waiting for some thing happen. When the disk block has been read or the character typed, the process waiting for it is unblock and is ready to run again. The process model, an integral part of a operating system, can be summarized as follows. The lowest level of the operating system is the scheduler with a number of processes on top of it. The scheduler does all the process handling, such as starting and stopping processes.

Process Control Block (PCB)

To implement the process model, the operating system maintains a table, an array of structures, called the process table. Each entry identifies a process with information such as process state, its program counter, stack pointer, memory allocation, the status of its open files, its accounting and scheduling information.

A Process Control Block (PCB, also called Task Control Block) is a data structure in the operating system kernel representing the state of a given process. Each process is identified with its own process control block, PCB, These are:

Implementations differ, but in general a PCB will include, directly or indirectly: ‰ The identifier of the process (a process identifier, or PID)

‰ Process state, which may be new, ready, running, waiting or halted; ‰ Register values for the process including, notably,

‰ The Program Counter value for the process

‰ The address space for the process. Memory management information, which include base and bounds registers or page table;

‰ I/O status information, composed I/O requests, I/O devices allocated to this process, a list of open files and so on;

‰ Process accounting information, such as when the process was last run, how much CPU time it has accumulated, etcetera.

During a context switch, the running process is stopped and another process is given a chance to run. The kernel must stop the execution of the running process, copy out the values in hardware registers to its PCB, and update the hardware registers with the values of the new process. A PCB structure is shown in Fig. 4.2

Pointer State Process number Program counter

Registers

Memory limits List of open files

Figure: 4.2: Process Control Block Structure

In another words, it must contain everything about the process that must be saved when the process is switched from the running state to the ready state so that it can be restarted later as if it had never been stopped. The switching between two processes is illustrated by Fig. 4.3.

Associated with each I/O device is a location near the bottom of memory called the interrupt vector. It contains the address of the interrupt service procedure. Suppose a user process j is running when a network interrupt occurs. The program counter, program status word, and possibly one or more registers are pushed onto the stack by the interrupt hardware. The CPU then jumps to the address specified in the network interrupt vector. The network interrupts service procedure starts out by saving all the registers in the process table entry for the current process. The current process number and a pointer to its entry are kept in global variables, so they can be founded quickly. The information deposited by the interrupt is removed from the stack, and the stack pointer is set to a temporary stack used by the process handler.

Now the network process can be started; it is changed from blocked to ready, and the scheduler is called. Normally, different processes have different priorities. If the network process is now the highest priority runnable process, it will be scheduled to run. If the process that was interrupted is just as important or more so, then it will be scheduled to run again, and the network process will have to wait a little while.

save register reload register

Process A

Process B

save register reload register

Executing

Executing

Executing

Idle

Idle

Idle

Figure: 4.3: Process switching

A process may create several new processes during its time of execution. The creating process is called parent process, while the new processes are called children processes. There are different possibilities concerning creating new processes:

‰ Execution: the parent process continues to execute concurrently with its children processes or it waits until all of its children processes have terminated (sequential). ‰ Sharing: either the parent and children processes share all resources (likes memory or

files) or the children processes share only a subset of their parent's resources or the parent and children processes share no resources in common.

A parent process can terminate the execution of one of its children for one of these reasons: ‰ The child process has exceeded its usage of the resources it has been allocated. In

order to do this, a mechanism must be available to allow the parent process to inspect the state of its children processes.

‰ The task assigned to the child process is no longer required.

We distinguish between independent process and cooperating process. A process is independent if it cannot affect or be affected by other processes executing in the system. This type of processes has following features:

‰ Its state is not shared in any way by any other process.

‰ Its execution is deterministic, i.e. the results of execution depend only on the input values.

‰ Its execution is reproducible, i.e., the results of execution will always be the same for the same input.

‰ Its execution can be stopped and restarted without any negative effect.

In contrast to independent processes, cooperating processes can affect or be affected by other processes executing in the system. They are characterized by:

‰ Their states are shared by other processes;

‰ Its execution is not deterministic, i.e., the results of execution depend on relative execution sequence and can not be predicted in advance;

Its execution is irreproducible, i.e., the results of execution are not always the same for the same input.

Scheduling: A Few Scenarios

The OS maintains the data for processes in various queues. The OS keeps the process identifications in each queue. These queues advance based on some policy. These are usually referred to as scheduling policies. To understand the nature of OS's scheduling policies, let us examine a few situations we experience in daily life. When we wish to buy a railway ticket at the ticket window, the queue is processed using a ``all customers are equal policy '' i.e. first-come-first- served (FCFS). However, in a photocopy shop, customers with bulk copy requirements are often asked to wait. Some times their jobs are interrupted in favor of shorter jobs. The operators prefer to quickly service short job requests. This way they service a large number of customers quickly. The maximum waiting time for most of the customers is reduced considerably. This kind of scheduling is called shortest job first policy. In a university department, the secretary to the chairman of department always preempts any one's job to attend to the chairman's copy requests. Such a pre-emption is irrespective of the size of the job (or even its usefulness some times). The policy simply is priority based scheduling. The chairman has the highest priority. We also come across situations, typically in driving license offices and other bureaus, where applications are received till a certain time in the day (say 11:00 a.m.). All such applications are then taken as a batch. These are processed in the office and the out come is announced for all at the same time (say 2:00 p.m.). Next batch of applications are received the following day and that batch is processed next. This kind of scheduling is termed batch processing. In the context of processes we also need to understand preemptive and non-preemptive operations. Non-preemptive operations usually proceed towards completion uninterrupted. In a non preemptive operation a process may suspend its operations temporarily or completely on its own. A process may suspend its operation for IO or terminate on completion. Note neither of these suspensions is forced upon it externally. On the other hand in a preemptive scheduling a suspension may be enforced by an OS. This may be to attend to an interrupt or because the process may have consumed its allocated time slot and OS must start execution of some other process.

Process Scheduling

Basic concepts

The assignment of physical processors to processes allows processors to accomplish work. The problem of determining when processors should be assigned and to which processes is called

In document computer fundamentals (Page 52-66)