OS
OS
BY
YASIR AHMED KHAN
Definition-Explanation of Operating System and Role of Operating System: Definition and Explanation: An operating system is a program that acts as an interface between the user of computer and the hardware. The purpose of an operating system is to provide an environment in which a user may execute programs. An operating system is an important part of almost every computer system. A computer system can roughly be divided into three components: Hardware: Hardware provides basic computing resources. It includes memory, CPU, arithmetic-logic unit, various storage devices, I/O, peripheral devices etc. Systems Programs: System programs manage the use of hardware among various application programs for various users. System programs include operating system, compilers, editors, loaders, utilities etc,
Application Programs: Application programs define the ways in which system resources are used to solve computing problems of the users. Application programs include database systems, business programs etc. Users: The users include people, machines and other computers. The central processing unit (CPU) is located on chips inside system unit. CPU is the brain of computer. This is the place where computer interprets and processes information. The operating system is the important component of the systems programs. Systems programs are directly executed on computer hardware. It enables application programmers and other users to access the power of computer fully and efficiently. Systems programming is different from application programming. It requires deeper knowledge of computer hardware. The system programs are often large and more complex. System programs provide the foundation on which the application programs are built. So the systems programs must be reliable, efficient and correct. Role of Operating System: The hardware provides the basic computing resources in a computer system. The applications programs define the way in which these resources are used to solve computing problems of the users. The operating system controls and coordinates the use of the hardware among various systems programs and application programs for various users. The role of operating system can be defined in the following ways: 1. Government: Operating system works as a government. The basic resources of computer system are provided by its hardware, software and data. It performs no useful function on its own. It actually provides the means and the environment for proper use of its resources. 2. Resource Allocator: A computer system has many resources. Each resource can be used to solve a problem. The operating system is responsible for managing the use of system resources. There may be many requests for a particular resource. These requests may be conflicting. The operating system decides which request should obtain the required resource. The operating system should take into consideration both system efficiency and fairness to individual requests. 3. Control Program: An operating system is a control program that prevents errors. It ensures that the system resources are not used improperly. There is no completely adequate definition of what is part of the operating system and what is not. Some people consider that text editors and other utility programs provided by the vendor is part of operating system. A more generally accepted definition of the operating system is that it is the program that is running at all times on the computer. This program is usually small and is commonly known to as kernel. Anything that is not part of the kernel is an application program. The primary goal of an operating system is convenience for user. Operating systems exist because they make it easier to compute. This is particularly clear when you look at operating system for small personal computers.
A secondary goal is the efficient operation of a computer system. It is particularly important for large, shared multi-user systems. Operating systems can solve this goal. It is known that sometimes these two goals, convenience and efficiency, are contradictory. An operating system is a group of programs designed to serve two basic purposes: 1. To control the allocation and use of the computing system's resources among the various users and tasks. 2. To provide an interface between the computer hardware and the programmer. The programmers create code, debug and maintain application programs. An effective operating system should accomplish all of the following tasks: Facilitate creation and modification of program and data files through an editor program. Provide access to compilers to translate programs from high-level languages to machine language. Provide a loader program to move the complied program code to the computer's memory for execution. Provide routines that handle the complicated details of I/O programming Assure that when there are several active processes in the computer, each will get fair chance to get the CPU. Take care of storage and device allocation. Provide for long term storage of user information in the form of files. Permit system resources to be shared among users when appropriate, and be protected from unauthorized or mischievous intervention as necessary.
Systems programs like translators and utility programs are not usually considered part of operating system. An operating system is responsible for providing access to these system resources.
Different Mainframe Systems: Mainframe systems were used to solve commercial and scientific problems. Following is the brief description of this type of systems. 1. Simple Batch Systems: Early computers were run from console. The card readers and tape drives were input devices. Line printers, tape drives and card punched were common output devices. The user did not interact directly with computer system. The user prepared a job that consisted of program, data and some control information (control cards). He then submitted it to the computer operator in the form of punched cards. The operating system was simple. Its basic job was to transfer control automatically from one job to the next. The operating system was always resident in memory. The operator batched similar jobs together and then ran in the computer to speed up the processing.
The CPU is often idle in this environment as speed of I/O devices is much slower than CPU. After sometime, the introduction of disk instead of card reader resulted in faster I/O devices. In disk technology, the operating system keeps all jobs on a disk instead of card reader. The resources are utilized and jobs are performed more efficiently with the help of job scheduling. Job scheduling is possible because all jobs are present on the disk. The memory contains operating system in one part and user program in other part. The user space can contain only one process at a time in batch system. Digital Equipment's VMS is an example of a batch operating system. 2. Multi-Programmed Systems: A group of jobs that are ready to be executed is called job pool. Since there is more than one job that can be executed, it is possible for the operating system to make a decision about which job to execute next. That decision keeps CPU utilization as high as possible. In general, it is not possible for a single user to keep CPU or I/O devices busy at all times. Multiprogramming allows the system to increase CPU utilization by ensuring that the CPU always has a job to execute. The CPU has a pool of jobs. When the currently executing job has to wait (if it is performing some I/O), it is removed from the CPU. Another job is selected and the CPU now executes it. This process ensures that CPU is always executing a job if there is a job to execute. In a non-multiprogrammed system, if a job had to wait for an I/O operation, CPU would also have to wait until I/O was finished. CPU requires sophisticated data structures to implement multiprogramming. CPU must be able to decide which job is to be executed next. Some jobs will fit into memory at once. Some jobs may have to remain on disk. The operating system must be able to perform some sort of scheduling on the jobs in job pool. It determines which jobs will slay on the disk and which ones will be loaded, into memory. The operating system must have some form of memory management. Memory management is used to keep track of which jobs are stored where and how much space is available. Sometimes, there may be many jobs that can run at any one time. The interaction between jobs must be controlled. In general, one job should not be able to manipulate the data or program code of another job. 3. Time Sharing: In batch system, the user cannot interact with the job when it is being executed. It means that all possible problems must be anticipated beforehand as the user cannot make corrections during execution. It becomes very difficult when a program has to go through many phases such as compilation, linking etc. It may be difficult to define what to do if a particular phase fails. Another problem is the debugging of a program. All debugging is static. The only information to find out is why the program is giving incorrect output at various stages of execution. Time sharing was introduced to make computer systems more interactive. CPU is the most important resource that is shared. Each job gets CPU for a small amount of time. When the allotted time period for a job is used, the next job in line is allocated CPU. The switching between jobs occurs very frequently. It allows the user to interact with the job as it. is running. Operating system should enable the user to interact with jobs that are executing. The communication usually occurs via keyboard. The user gets a prompt to enter commands. The user must know the status of the job in order to enter relevant commands. The output of a job is usually presented on a monitor.
Generally, the commands given by the user take very little time to execute. The control returns to command line after finishing a command. It displays a prompt to indicate that the system is ready to execute another command- DOS and Unix are examples of such of system. 4. Time Sharing Systems: Time sharing system is a multi-user, multi-process and interactive system. It allows multiple users to share computer simultaneously. It is used when several users are linked through communication networks to a single computer. The computer first works on one user's task for a fraction of time. It then goes to the next user's task. It is accomplished through time slicing. Each task gets a time slice in round robin fashion. The task continues until the time slice ends. The task stops when the given time slice is finished and waits for another time slice. The computer operates very quickly and can distribute time slices to various tasks. The computer rapidly switches back and forth among different tasks. Time sharing systems use CPU scheduling and multiprogramming to provide each user with a small portion of time shared computer. The CPU can be allocated to a job only if that job is currently in memory. A time sharing system is very complex. It is more complex than a multiprogrammed system. It must be able to have several jobs ready in memory simultaneously. It requires some form of memory management and protection. Jobs must be swapped in and out in a reasonable time. It may be achieved by using virtual memory. Virtual memory is a technique that allows the execution of a job that may not be completely in the memory. Unix, Linux, Windows NT Server and Windows 2000 Server are examples of time sharing systems.
Personal Computer Systems in Operating System: Computer hardware in the past has been very expensive. A single machine might have many users to keep costs down. This resulted in operating systems focusing mainly on efficiency and protection. It is now possible for individuals to have separate machines as the hardware has become cheaper. The operating systems for personal computers can adopt technology that was originally developed for larger operating systems. Personal computer systems are primarily designed for a single user environment. They are not too concerned with protection because only one user accesses the machine.
Multiprocessor Systems: Multiprocessing is a type of processing in which two or more processors work together to process more than one program simultaneously. It allows the system to do more work in a shorter period of time. UNIX is one of the most widely used multiprocessing systems.
Multiprocessor system is also known as parallel system or tightly-coupled system. It means that multiple processors are tied together in some manner. Generally, the processors are in close communication with each other. They share common data structures and a common system clock. Advantages of Multiprocessor Systems: Some advantages of multiprocessor system are as follows: Reduced Cost: multiple processors share the same resources. Separate power ;supply or mother board for each chip is not required. This reduces the cost. Increased Reliability: The reliability of system is also increased. The failure of one processor does not affect the other processors though it will slow down the machine. Several mechanisms are required to achieve increased reliability. If a processor fails, a job running on that processor also fails. The system must be able to reschedule the failed job or to alert the user that the job was not successfully completed. Increased Throughput: An increase in the number of processes completes the work in less time. It is important to note that doubling the number of processors does not halve the time to complete a job. It is due to the overhead in communication between processors and contention for shared resources etc.
Types of Multiprocessor Systems: There are two main types of parallel processing: 1. Symmetric Multiprocessing: A method of processing in which multiple processors work together on the same task is called symmetric multiprocessing. Each processor runs an identical copy of the same operating system. Symmetric multiprocessing treats all processors equally. I/O can be processed on any processor. The processors communicate with each other as needed. It enables many processes to be run at once without degrading performance. Each CPU is separate, it is possible for one CPU to be idle while another CPU is overloaded. Symmetric multiprocessing is easier to implement in operating systems. It is the method mostly used by the operating systems that support multiple processors. The most common multiprocessor systems today use SMP architecture. 2. Asymmetric Multiprocessing: A multiprocessing technique in which individual processors are dedicated to particular tasks such as running the operating system or performing user requests is called asymmetric multiprocessing. It has one master processor and remainder processors are called slave. The master distributes tasks among the slaves. I/O is usually done by the master only. An example is disk management where the responsibility of managing disk activities is not handled by main processor. It is performed by a microprocessor that has its own memory. It only performs disk management tasks such as how to move the head of disk to read data from disk into memory etc.
Definition and Explanation of Distributed Systems in Operating System: Definition and Explanation: A system that distributes the computation among several physical processors is called distributed system. It is known as loosely-coupled. It means that the processors do not share memory; data structures or system clock. Each processor has its own local memory. It can only communicate with other processors through a communication line usually over a network. The processors in distributed system may vary in size, speed and function. Advantages of Distributed Systems: The main advantages of building distributed systems are as follows: 1. Resource Sharing: Each computer in the distributed system may have specific resources. Other machines may utilize its resources while being part of the distributed system. 2. Computation Speedup: If a computation can be split up into sections, it is possible to give different sections to different machines. Communication is usually fairly expensive since the machines may not be physically close to each other. 3. Reliability: It provides more reliability for different jobs. If one system fails, the other sites may be able to continue processing.
Clustered Systems in Operating System: A clustered system uses multiple CPUs to accomplish a task. It is different from parallel system in that clustered system consists of two or more individual systems coupled together. The clustered computers share storage and are closely linked via LAN networking. The clustering is usually performed to provide high availability. A layer of cluster software rims on cluster nodes. Each node can monitor one or more nodes over the LAN. The monitored machine can fail in some cases. The monitoring machine can take ownership of its storage. The monitoring machine can also restart applications that were running on the failed machine. The failed machine can remain down but the users will see a brief of the service. Types of Clustered System: The clustered system can be of the following forms: Asymmetric Clustering: In this form, one machine is in hot standby mode and other machine is running the application. The hot standby machine performs nothing. It only monitors the server. It becomes the active server if the server fails. Symmetric Clustering: In this mode, two or more machines run the applications. They also monitor each other at the same time. This mode is more efficient because it uses all available machines. It can be used only if multiple applications are available to be executed. Some other forms of clusters are parallel clusters and clustering over WAN. Parallel clusters allow multiple hosts to access the same data on a shared storage. Most operating systems do not provide the support for simultaneous data access by multiple hosts. That is why parallel clusters are usually
accomplished by special versions of software and special releases of applications. An example of such software is Oracle Parallel Server. It is a version of Oracle database that is designed to run on parallel clusters. Each machine runs Oracle and a layer of software tracks access to the shared disk. Each machine also has full access to all data in the database. Most clusters do not support shared access to data on the disk. The distributed file systems must provide access control and locking to the files to prevent conflicting operations. This type of service is commonly known as distributed lock manager (DLM).
Real-Time Systems in Operating System: A real time system is a system that ensures the exact time requirements for a job. If a real-time system does not complete a task in a certain time, it may cause a break down of the entire system it is running. Some applications require to be serviced within a time period: Industrial control systems Automobiles (brakes) Airplane guidance Medical devices
Types of Real-Time Systems: There are two types of real time systems: 1. Hard Real Time Systems: A hard real time system guarantees that a job will complete within a specified time period. This system must ensure that all delays on processing, input and output are bounded. The system cannot wait indefinitely so the hard time systems are usually very limited. There is generally no secondary storage such as disk drives as a disk request can take a variable time to process. Some examples of a hard real time system are the software that run the autopilot in an jumbo jet or the imaging software on a missile. 2. Soft Real Time Systems: A soft real time system is a much less restrictive version of a hard real time system. A soft real time system does not guarantee that a job will complete within a specified time period. However, it tries its best to finish the job as soon as possible. If a critical real time job enters the system, the operating system may assign the highest priority to that task and execute it continuously until it completes. The lack of a guarantee makes a soft real time system more limited in its application for industrial activities. Soft real time systems are used in multimedia, virtual reality etc. The operating systems that provide soft real-time support are Windows NT/2000, Linux, Solaris.
Interrupts in Operating System: Definition and Explanation: An interrupt is a hardware-generated change-of-flow within the system. An interrupt handler deals with the cause of the interrupt. The control is then returned to the interrupted context and instruction. Functions of Interrupts: Each computer architecture has its own interrupt mechanism but they all have several functions in common. Below is a brief list of the common functions of interrupts: When an interrupt occurs, the control is transferred to the interrupt service routine. The interrupt service routine is generally accessed through an interrupt vector. Interrupt vector knows where to find the appropriate interrupt service routine for the current interrupt. The interrupt architecture must save the address of the instruction that has been interrupted (the program counter). Incoming interrupts must be disabled if there is an interrupt currently being processed. This is to prevent interrupts from being lost or overwritten by newly arriving interrupts. An interrupt is generally caused by a hardware device such as a device driver letting the CPU know that some data has been read from the device and is waiting in the local device buffer. A trap is a software-generated interrupt that is either caused by an error or by a user request for an I/O operation. An operating system is interrupt driven. This means that if there are no interrupts, then the system will be idle. The operating system must preserve the state of the CPU by storing the contents of the registers and the program counter. The operating system must determine which type of interrupt has occurred. This can be done either by polling or by using a vectored interrupt system. Polling is the systematic checking of each device to see if it was the device responsible for generating the interrupt. If the operating system has a vectored interrupt system, then the identity of the device and the type of interrupt will be easily identifiable without checking each device. The operating system must provide a segment of code that specifies what action is to be taken in the event of an interrupt. There must be a code segment that is specific to each type of interrupt.
Supervisor Call Interrupts (SVC): These interrupts are initiated by a running process that executes SVC instruction. It is a user request for a particular system service such as performing I/O or obtaining more storage etc. I/O Interrupts: These are initiated by I/O. hardware. These interrupts send signal to CPU to indicate that the status of a channel or device has changed. I/O interrupts occur when I/O operation completes, I/O error occurs or a device gets ready etc. External Interrupts: These are caused by different events. These events can the" expiration of a quantum on interrupting clock, pressing of interrupt key or receipt of a signal from another processor in a multiprocessor system etc. Restart Interrupts: These interrupts occur when the restart button of console is pressed or restart signal is received from another processor in multiprocessor system. Program Check Interrupt: These are caused by different problems during the execution of machine language instructions. Some problems include division by zero, arithmetic overflow or underflow, wrong format of data etc. Machine Check Interrupts: These are caused by the hardware that does not function, properly.
Operating System Mode: Operating system must provide multiple modes of execution that are as follows: Kernel Mode, Supervisor Mode or System Mode. User Mode.
A special bit is used to indicate the execution mode of the system. Some restricted activities can only be executed in kernel mode. Such activities include the execution of certain priviledged instructions, accessing certain registers and accessing I/O devices etc. If these instructions are executed in user mode, a trap is generated. A system enters kernel mode in the following three ways: A special instruction called supervisor call or system call can be used to set the system in kernel mode. A trap can be used to set the system in kernel mode. An interrupt can be used to set the system in kernel mode.
Operating System Components: An operating system has many components to manage all resources of computer system while ensuring proper execution of programs. The list of operating system components is as follows:
1. Process Management: A process is a program in execution. A process needs certain resources, including CPU time, memory, files and I/O devices in order to accomplish its task. The operating system is responsible for the following activities in connection with process management: Process Creation Process Deletion Process Suspension Process Resumption Provision of a mechanism for process synchronization Provision of a mechanism for process communication
2. Main Memory Management: memory management is a process of optimizing the use of main memory. RAM is used, to store data and instructions temporarily during execution. Operating system allocates memory area to different programs. The allocated memory area is De-allocating when the program finishes. Some operating systems allocates a part of storage medium like hard disk as additional RAM. A part of a running program can be in RAM and the remaining part may be on hard disk. This is known as virtual memory. The area of hard disk used for virtual memory is called swap file. It is used to exchange data, information, and instructions between memory and hard disk. The amount of data and program instructions that can swap at a given time is called page. The process of swapping items between memory and hard disk is called paging. A situation in which most of the time of operating system is wasted in paging instead of executing the program is called thrashing. The operating system is responsible for the following activities in connection with memory management: Keeping track of which parts of memory are currently being used and by whom. Deciding which processes to load when memory space becomes available. Deciding how much memory is to be allocated to a process. Allocating memory space as needed. De-allocating memory space as needed.
3. Secondary Storage Management: Main memory or primary storage is volatile and too small to accommodate all data and programs permanently. The computer system must provide secondary storage to back up main memory. Most modern computer systems use disks as the principle storage medium for both programs and data. The operating system is responsible for the following activities in connection with disk management: Free space management Storage allocation and de-allocation
Disk Scheduling
4. I/O System Management: The role of operating system in I/O system is to manage and control I/O operations and I/O devices. One goal of I/O is to provide the simplest interface and to optimize I/O for maximum concurrency. The I/O system manages different I/O devices such as mouse, keyboard, monitor and printer etc. The I/O system consists of the following: A buffer caching system A general device driver interface Drivers for specific hardware devices
5. File Management: A file is a collection of related information defined by its creator. A file can be a program like word processing program. It can be a data file like images, songs etc. A file management system is a system software that provides services to the user and applications related to the use of file. The operating system is responsible for the following activities in connection with file management: File creation File deletion Directory creation Directory deletion Support of primitives for manipulating files and directories Mapping files onto secondary storage
File backup on stable (non-volatile) storage media 6. Protection System: If a computer system has multiple users and allows concurrent execution of multiple processes, the processes must be protected from each other's activities. The protection refers to a mechanism to control access by programs, process or users to the system and resources. The protection mechanism must: Distinguish between authorized and unauthorized usage Specify the controls that are to be imposed Provide a means of enforcement
7. Networking (Distributed Systems): A distributed system is a collection of processors that do not share memory or a clock. Each processor has its own memory. The processors in the system are connected through a communication network. A distributed system provides access to various system resources. The access to a shared resource allows: Computation speed-up Increased data availability Enhanced reliability
8. Command Interpreter System: Command interpreter is an interface between the user and operating system. It is one of the most important system programs for operating system. It is used to read and execute user commands. Some operating system provide command interpreter in the kernel. The command interpreter system is also known as command-line interpreter or shell. Many commands are given to operating system by control statements which deal with following: Process creation and management. I/O handling Secondary storage management Main memory management File-system access Protection Networking
The program that reads and interprets control statements has many different names. Some of these are: Control card interpreter Command line interpreter Shell (in Unix)
The function of this program is to get and execute the next command statement.
Role of Kernel in Operating System: The kernel provides the most basic interface between the computer itself and the rest of the operating system. The kernel is responsible for the management of the central processor. The kernel includes the dispatcher to allocate the central processor, to determine the cause of an interrupt and initiate its processing, and some provision for communication among the various system and user tasks currently active in the system. Functions of Kernel in Operating System: Kernel is the core of an operating system. The main functions of kernel are as follows: It provides a mechanism for creation and deletion of process. It provides CPU scheduling, memory management and device management for these processes. It provides synchronization tools so that the processes can synchronize their actions. It provides communication tools so that processes can communicate with each other.
Scheduling is a fundamental operating system function. Almost all computer resources are scheduled before use. CPU is one of the primary computer resources. Its scheduling is often performed in the operating system.
The kernel-based design is often used to design operating system. The kernel (also called nucleus) is a set of primitive facilities over which the rest of operating system is built. A kernel provides an environment to build an operating system in which the designer has considerable flexibility. The policy and optimization decisions are not made at kernel level. An operating system is an orderly growth of software over kernel where all decisions regarding process scheduling, resource allocation, execution environment, file system and resource protection etc. are made. The kernel only support the notion of processes. It does not include the concept of a resource. Operating systems have matured in functionality and complexity and more functionality has been relegated to the kernel. A kernel should contain a minimal set of functionality that is adequate to build an operating system with a given set of objectives.
Operating System Services for Process Management: Below is a list of selected operating system services: Program Execution: The operating system must provide the ability to load a program into memory and to run it. I/O Operations: The operating system must provide this capability since users cannot perform I/O directly. File System Manipulation: The operating system must provide the capability to read, write, create and delete files from a user program. There are many details in file creation, deletion, allocation, and naming that users should not have to perform. Blocks of disk space, are used by files and must be tracked. Deleting a file requires removing the name file information and freeing the allocated blocks. Protections must also be checked to assure proper file access. Communications: It is the exchange of information between processes that may be executing on the same computer or on completely different machines. This is usually implemented via shared memory or message passing. Error Detection: It is the ability to detect errors in CPU, memory hardware, I/O devices or in user programs. Error detection occurs at both hardware and software levels. At hardware level, all data transfers must be checked to ensure that data have not been corrupted or changed. At software level, media must be checked for data consistency. For example, the number of allocated and unallocated blocks of storage . should match the total number of blocks on the device. Some additional operating system services that do not help the user but ensure that the machine runs efficiently are as follows: Resource Allocation: It is the ability to allocate resources to multiple users or to multiple jobs running at the same time.
Accounting: It is the ability to keep track of and to record which users use how much and what kinds of computer resources. Protection: It is the ability to ensure that all access to system resources is controlled.
System Calls in Operating System:System calls provide an interface between a running program and operating system. System calls are generally available as assembly language instructions. Several higher level languages such as C also allow to make system calls directly.The system call interface layer contains entry point in kernel code. All system resources are managed, by the kernel. Any request from user or application that involves access to any system resource must be handled by kernel code. The user process must not be given open access to kernel code for security reason. Many opening into kernel code called system calls are provided to user so that the user processes can invoke the execution of kernel code. System calls allow processes and users to manipulate system resources.There are three general methods that are used to pass information (parameters) between a running program and the operating system.One method is to store parameters in registers. Another is to store parameters in a table in memory and pass the address of table. The third method is to push parameters on stack and allow operating system to pop the parameters off the stack.Types of System Calls in Operating System:The main types of system calls are as follows:Process Control: These types of system calls are used to control the processes. Some examples are end, abort, load, execute, create process, terminate process etc.File Management: These types of system calls are used to manage files. Some examples are Create file, delete file, open, close, read, write etc.Device Management: These types of system calls are used to manage devices. Some examples are Request device, release device, read, write, get device attributes etc.Information Maintenance: These types of system calls are used to maintain information. Some examples are Get time or date, set time or date, get system data, set system data etc.Communications: These types of system calls are used to for communication. Some examples are Create, delete communication connection, send, receive messages etc.Process and Process Attributes in Operating System:Definition and Explanation:An operating system executes a variety of programs depending on the system. In batch system, a program is called job. In time-shared system, it might be called a user program or task. Normally, the terms job and process are used almost interchangeably.A more precise definition of the term process is that "A process is a program in execution". A process has a starting and ending place. It must execute and progress sequentially. At most, one instruction may be performed on behalf of the process at any given time. A process is controlled and scheduled by operating system.Process Attributes:A process has the following attributes:A program counter is used to keep track of the address of the next instruction to be executed. A stack is used to store temporary data for the process. A data section is used that may contain global variables.A program is a passive entity. It specifies the logic of data manipulation and I/O actions. A program does not perform the actions itself. It has to be executed to realize the action. A process is an active entity. It performs the actions specified in the program.Process States in Operating System:Process state describes the nature of current activity in a process. As process executes, its state changes. A process may be in one of the following states:New: The process is being created (it is not yet in memory)Running: The process has an instruction that is being executedWaiting (Blocked): The process is waiting for some event to occur.Ready: The process is waiting to be executedTerminated: The process has finished execution
and is no longer in memoryState Transition in Process/Operating System:Different state transitions in a process can be as follows:New Ready - Admitted to ready queue; can be considered by CPU scheduler.Ready Running - CPU scheduler chooses that process to execute next according to some scheduling algorithm.Running Ready - Process has used its current time slice.Running Blocked - Process is waiting for some event to occur e.g. for I/O operation to complete.Blocked Ready - Whatever event the process was waiting, has occurred.Process Control Block in Operating System:Process control block is a data structure. It contains all information for a process to be used for controlling its execution. It also contains the information related to the resource allocated to the process. Every process has its own PCB. The process control block is very important. It should be stored in protected area where the user cannot access it. The information that must be saved usually consists of the following:Process State: The state of the process (ready, waiting, etc.).Program Counter: The "program counter" of the PCB points to the next instruction to be executed when the process gains the CPU.CPU Register: The contents of CPU registers for the process (all the temporary data that will be destroyed by the next process that gets the CPU after an interrupt occurs).CPU scheduling Information: It holds information needed for CPU scheduling, such as process priority and any scheduling-queue pointers.Memory Management Information: Information required by the memory manager (base register, limit register, page table for this process, etc.).Accounting Information: This part of PCB holds the amount of CPU time and real time used by the process to date, the process number, and so forth.I/O Status Information: This part of the PCB holds a list of the I/O devices that the process has requested, a list of the process's open files, etc.Process Scheduling in Operating System:Process scheduling is a technique that is used when there are limited resources and many processes are competing for them. multiprogramming tries to ensure that there is some process running at all times. This is done to utilize the CPU as much as possible. In timesharing system, the CPU switches so frequently between jobs that the user does not feel that the machine is being shared by many processes or even many users.If the system has more than one processor, then it is possible to execute more than one process at the same time. In a single processor system, only one process can be executed at any given time. If there are more processes than processors, then the operating system must schedule the processes. It means that some processes will be executed and others will have to wait. There are many strategies for deciding which process should be assigned the CPU.
Scheduling Queues in process management: Below is a list of the most common types of queues and their purpose. Job Queue: Each entering process goes into job queue. Processes in job queue reside on mass storage and awaits the allocation of main memory. Ready Queue: The set of all processes that are in main memory and are waiting for CPU time, are kept in ready queue. Waiting (Device) Queues: The set of processes waiting for allocation of certain I/O devices, are kept in waiting device queue.
Process Migration between Various Queues: During its lifetime, a process begins in the job queue. It moves between the ready, waiting and possibly job queues and eventually finishes the task. This process of moving between various queues is known as process migration. Scheduler: When more than one processes can be executed, the operating system must decide which one to run first. The part of the operating system concerned with this decision is called the scheduler. The algorithm used by scheduler is called the scheduling algorithm. The operating system must perform three different kinds of scheduling: 1. Long Term Scheduling: It is also known as job scheduling. It selects a process when it should be brought from job queue into ready queue. Too many processes in memory slow down the machine. Too few means the machine is not being utilized efficiently. The long-term scheduler is invoked fairly infrequently and can be fairly slow. Processes are added to the system much less frequently than processes are swapped between the ready queue and CPU. The long-term scheduler usually has to make a more difficult decision than the short-term scheduler. The long-term scheduler controls the degree of multiprogramming i.e. the number of processes in memory. If there are too few .processes in memory, the system is under-utilized. If there are too many processes, the system may spend too much time swapping between process because of a lack of resources (memory,, disks, etc.). 2. Short Term Scheduling: It is also known as CPU scheduling. It selects a process from ready queue and gives' control of CPU to the process. The short-term, scheduler is invoked very frequently and must be very fast. Processes typically only hold the CPU for short periods of time. While the short-term scheduler is deciding which job to run next the system is not performing any useful work. 3. Medium Term Scheduling: It is also possible for an operating system to perform medium term scheduling. The medium term scheduler can remove processes from memory. It swaps the processes between memory and secondary storage. It improves the performance of the system by reducing the degree of multiprogramming. A process can be swapped out of the memory to adjust another process in the memory. Context Switch: Whenever the CPU switches to another process, the system must save the state of the old process and load the saved state of the new process. If context switch does not occur, the new process may use the data from the old one. It is probably not the same data that was left behind when it was last on the CPU. Whenever a context switch is performed, the CPU performs no useful work. This means that we would like the context switch to take as less as possible. The time that a context switch takes is dependent on whether there is some hardware available to support the switching (multiple sets of registers, etc.) As an operating system becomes more complex, the process needs to restore more information like memory management details etc.
Operations on Process in Process Scheduling: The operating system is responsible for providing a mechanism to create and destroy processes dynamically. Process Creation: Parent process creates children processes. The children processes can also create other processes forming a tree of processes. A process may create zero or more new child processes. Process creation may be limited by the amount of resources that a parent process has. If a parent process creates a child process, child process may create child processes of its own, creating a tree of processes. When a child process is created, it may be able to obtain resources directly from the parent. It may only be able to obtain a subset of the parent's resources or it must acquire its own resources. It is usually a good idea to limit the resources of child process as a single user process could create hundreds of child processes. Each might be able to acquire resources of their own, leaving no resources for other processes and effectively giving control of the machine to a single user process. When a process creates a new process, the parent may continue to execute concurrently with its children or it must wait until some or all its children have terminated execution. In terms of address space, the child may be an exact duplicate of the parent. This would allow the child and parent to communicate very easily as they share the same address space. It should be possible to load a new program into the address space of the child (typically we want the child to do something different to its parent). It is also possible to create an entirely new process and place a new program into it. This makes it more difficult for the child and parent to communicate since they have nothing in common. Process Termination: A process normally terminates when it has finished executing its last statement. It typically tells the operating system by issuing some form of the exit() system call. At this point, if the process is a child it may output some data to its parent. Eventually the process has all its resources removed from it and is no longer part of the job pool. A child process may be terminated by its parent using the abort () system call. This may occur because the child has asked for too many resources, the child is no longer wanted, or possibly if the parent is terminating. The operating system may or may not allow a child process to continue executing after its parent terminates. In some instances it does not make sense for the child to keep going, especially if its job was to compute something and to return a result. In other instance, a child process may continue after the parent has finished e.g. a web browser may allow you to download files in the background after the web browser has been closed.
Cooperating Processes in Operating System: Definition and Explanation: There are two kinds of processes: cooperating and independent processes. A process is independent if it cannot affect or be affected by other processes. A process is said to be a cooperating process if it can affect or be affected by other processes in the system. A process that shares data with other processes is cooperating and a process that does not share data is independent. Advantages of Cooperating Processes: There are some advantages of cooperating processes: information Sharing: Several users may which to share the same information e.g. a shared file. The O/S needs to provide a way of allowing concurrent access. Computation Speedup: Some problems can be solved quicker by sub-dividing it into smaller tasks that can be executed in parallel on several processors. Modularity: The solution of a problem is structured into parts with well-defined interfaces, and where the parts run in parallel. Convenience: A user may be running multiple processes to achieve a single goal, or where a utility may invoke multiple components, which interconnect via a pipe structure that attaches the stdout of one stage to stdin of the next etc. If we allow processes to execute concurrently and share data, then we must either provide some mechanisms to handle conflicts e.g. writing and reading the same piece of data. We must also be prepared to handle inconsistent or corrupted data. Example: Below is a very simple example of two cooperating processes. The problem is called the Producer Consumer problem and it uses two processes, the producer and the consumer. Producer Process: It produces information that will be consumed by the consumer. Consumer Process: It consumes information produced by the producer. Both processes run concurrently. If the consumer has nothing to consume, it waits. There are two versions of the producer. In version one, the producer can produce an infinite amount of items. This is called the Unbounded Buffer Producer Consumer Problem. In the other version, there is a fixed limit to the buffer size. When the buffer is full, the producer must wait until there is some space in the buffer before it can produce a new item. Bounded Buffer - Shared Memory Solution: Here is a shared memory solution for Bounded Buffer Producer Consumer problem. Both processes have some shared data that can be accessed and updated. The shared data is as follows: // Shared data: int n = 5, item, in, out; // number of items in buffer is at most 5 int buffer[n]; // both the consumer and producer are currently looking at buffer element 0. in = 0; out = 0;
// Producer Process . while (true) { while (in+1 % n == out) { // Do nothing } // produce a random item buffer[in] = nextProduction; in = in + 1 % n; } / / Consumer process while (true) { while (in = = out) { //Do nothing . } nextConsumed = buffer [out]; out = out + 1 % n; } The producer basically just checks to see if there is any space in which to put a newly produced item (outer while loop). If there is no space, then it waits, until there is some space. The consumer waits while the buffer is empty. If there is something/ it grabs the next item and consumes it. One drawback with this solution is that there is one element of the buffer that is wasted.
Inter-Process Communication (IPC) in Operating System: Sometimes cooperating processes may need to communicate with each other without using a shared buffer. This can be achieved by allowing processes to send messages to each other through some form of message passing system. Note that a message passing system and a shared buffer are not mutually exclusive. Inter-process communication can be used for processes to communicate or to synchronize their actions. An IPC facility provides two operations of sending and receiving message. If two process wish to communicate they need to: Establish a communication link between them. Exchange messages using the send and receive operations.
There must be some form of communication link between processes like such as shared memory or a hardware bus.
Implementation Questions: There are several implementation questions that need to be asked about communication links between processes. Some of these are: How are links established? Can a link be associated with more than two processes. How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional?
Direct Communication: In direct communication, processes that wish to communicate with each other must know each other's names. When they communicate, they must name each other explicitly. Otherwise, the message may not be delivered correctly. The two operations in a direct communication system may be defined as: Send (ProcessName, message) Receive (ProcessName, message)
The links in a direct communication environment are established automatically. A link is associated with exactly one pair of communicating processes, and between each pair there exists only one link. The link may be unidirectional or bi-directional. Indirect Communication: In indirect communication, messages are received from mailboxes also known as ports. Each mailbox has a unique ID. Processes can communicate only if they share a mailbox. The links in an indirect communication environment are established only if processes share a common mailbox. A link may be associated with many processes and each pair of processes may share several communication links. The links may be unidirectional or bidirectional. In addition, some extra operations are needed: Create a new mailbox. Send and receive messages through a mailbox. Delete a mailbox.
Some problems with the mailbox system occur when more than two processes share a mailbox. Process 1 sends a message to a mailbox that it shares with Process 2 and Process 3. Process 2 and Process 3 both try to receive the message. Who gets it? Some solutions to the above problem are: To allow a link to be established with at most two processes. To allow only one process at a time to execute a receive operation. To allow the system to arbitrarily select the receiver (the sender must be notified who received the message).
Buffering: If many messages are sent at once and we do not want to lose messages, the link may have a buffer attached to it. A buffer is just like a queue of messages. The buffer may have one of three properties: Zero Capacity: 0 messages can be stored in the buffer. The sender must wait for the receiver to respond (rendezvous). Bounded Capacity: Finite length of n messages. Sender must wait if the buffer is full. Unbounded Capacity: Infinite number of messages may be stored. The sender never has to wait.
Introduction to threads/Lightweight Process: A thread is a basic unit of CPU utilization. It is also called a lightweight process. A thread is a sequence of instructions within a process. A thread behaves like "a process within a process" but it differs from a process in that a thread does not have its own PCB. Usually multiple threads are created within a process Threads are different kind of program executing within process. Processes are programs in execution within kernel. Thread consists of the following: ThreadID Program Counter Register Set Stack
A thread shares some things with its peer threads (all the other threads in this particular task). The things that it shares are: Code Section Data Section Any operating system resources, which are available to the task
A traditional heavyweight process is the same as a task with one thread. The term thread really refers to thread of execution. A multi-threaded process means that more, than one part of the same process may be running at one time. In a multi-threaded task, one server thread may be blocked and waiting for something and another thread in the same task may be running. If a heavyweight process blocks then the whole process stops. Multithreading is useful in programs such as web browsers where you may wish to download a file, view an animation and print something at the same time.
When multiple threads cooperate in a single job, there is a higher throughput. If one thread must wait, the whole process does not stop. Another thread may still run. Applications that require sharing a common buffer (such as the producer consumer problem) may benefit from using threads. Types of Threads: Threads may be handled at different levels. 1. Kernel-Level Threads: Kernel-supported threads are seen by the operating system and must be scheduled by the operating system. One multithreaded process may have multiple kernel threads. 2. User-Level Threads: User-level threads are not seen by the operating system and are also very fast. Switching from one thread to another in .a single process does not require a context switch since the same process is still executing. However, if the thread that is currently executing blocks, the rest of the process may also be blocked if the operating system sees only one kernel thread for this process. The thread that the kernel sees is the same as the blocked thread, hence the kernel assumes that the whole process is blocked.
Advantages of Multithreading: Some advantages using multithreading are as follows: 1. Responsiveness: Multithreading approach increases responsiveness of the process. As a process consists of more than one thread, if one thread is blocked or busy in a lengthy calculation, some other thread may still be executing. So the user gets more response from the executing process. For example, a browser allows a user to interact with it while a file is being downloaded. 2. Resource Sharing: All threads of one process share the memory and resources of that process. Secondly it allows an application to have several different threads within the same address space. 3. Economy: Allocation of memory and resources for process creation is costly. All threads of a process share the resources of that process so it is more economical to create and context switch the thread. 4. Utilization of Multiprocessor Architecture: Multiprocessor architecture allows the facility of parallel processing. It is most efficient way of processing. A single threaded process can be executed on one CPU even if we have more processors. Multithreading on a multiprocessor system increases concurrency. Different parts of a multithreaded process can be executed simultaneously on different processors.
1. Many-to-one Model: In Many-to-one Model, many user level treads are mapped to one kernel thread. It is efficient because it is implemented in user space. A process using this model will be blocked entirely if a thread makes a blocking system call. Only one thread can access the kernel at a time so it cannot be run in parallel on multiprocessor. 2. One-to-one Model: In this model, each user thread is mapped to a kernel thread. It provides more concurrency because it allows another thread to execute when a thread makes a blocking system call. It facilitates parallelism in multiprocessor. Each user thread requires a kernel thread which may affect the performance of the system. Creation of threads in this model is restricted to a certain number. This model is used by Windows NT, Windows 2000 and OS/2. 3. Man-to-Many Model: This model multiplexes many user level threads to a smaller or equal number of kernel threads. The number of kernel threads may be specific to either a particular application or a particular machine. The user can create any number of user threads and corresponding kernel threads can run in parallel on multiprocessor. When a thread makes a blocking system call, the kernel can execute another thread. It is used by Solaris 2, IRIX, and Tru64.
Definition and Explanation of CPU Scheduling in Operating system: A major task of an operating system is to manage a collection of processes. In some cases, a single process may consist of a set of individual threads. In both situations, a system with a single CPU or a multi-processor system with fewer CPU's than processes has to divide CPU time among the different processes /threads that are competing to use it. This process is called CPU scheduling.
Definition and Explanation of Multiprogramming in Operating system:The operating system can make the computer more productive by switching the CPU among processes. The objective of multiprogramming is to have some process running at all times. This should maximize CPU utilization. If there is only one processor (or CPU) then there will only be one process in a running state at any given time. If there are more processes that need to be run, they will have to wait. There must be some mechanism to select which process (currently in memory) will run next when the CPU becomes available.The operating system maintains a ready-queue. Processes on this queue are ready to be executed. Whenever a currently executing process needs to wait (does I/O etc.), operating system picks a process from the ready queue and assigns the CPU to that process.Scheduling is a fundamental operating system function. CPU is an important resource. It is very important to develop good scheduling algorithms.Example:Suppose we have two processes A and B. Each process executes for one second then waits for one second. It is repeated 60 times. If we run process A first and then process B, one after the other, it will take four minutes to run the two processes: A takes two minutes to run and then B takes two minutes to run. We actually compute only two minutes of this time. The other two minutes are idle time. Our CPU utilization is only 50%.Scheduling Objectives in Process:Schedulers typically attempt to achieve some combination of the following, goals. Note that, to some extent, these goals are contradictory:Maximize CPU
utilization (due to its relatively high cost). Maximize utilization of other resources (disks, printers etc.). Maximize throughput = number of jobs completed per unit time. Minimize waiting time = total time a job spends waiting in the various queues for a resource to become available. Minimize turnaround time = waiting time + computation time + I/O time. Minimize response time (timesharing) = time from entry of a command until first output starts to appear. Fairness: All comparable jobs should be treated equally. Avoid indefinite postponement: It is normally avoided by using aging. In aging, the priority of a process, grows as it waits for a resource. The priority slowly becomes highest and it gets the resource. Uniformity: The behavior of the system should be predictable. Graceful degradation: The system, response deteriorates gradually rather than coming to a sudden virtual standstill in case of excessive loads. Predictably: A given job should run in about the same amount of time and at about same cost regardless of system load.CPU I/O Burst Cycle:The execution of a process consists of an alternation of CPU bursts and I/O bursts. A process begins and ends with a CPU burst. In between, CPU activity is suspended whenever an I/O operation is needed.If the CPU bursts are relatively short compared to the I/O bursts, then the process is said to be I/O bound. For example, a typical data processing task involves reading a record, some minimal computation and writing a record. If CPU bursts are relatively long compared to I/O bursts, a process is said to be CPU bound. A number crunching task involves an I/O burst to read parameters. A very long CPU burst and another I/O burst is required to write results.Dispatcher in Operating System:Definition and Explanation:Dispatcher is a program that actually gives control of CPU to a process selected by CPU scheduler. It is another part of the scheduling system.The functions of dispatcher module are as follows:Switching context Switching to user mode Jumping to the proper location in the user program to restart itThe dispatcher should be very fast because it is called every time a process takes control of CPU. The time that the dispatcher takes between stopping one process and starting another process is called the dispatch latency.