Unit - 1
Operating Systems
Q1) What is the operating system?
A1) An OS (OS) is associate degree interface between a soul and hardware. Associate degree OS is software package that performs all the fundamental tasks like file management, memory management, method management, handling input and output, and dominant peripheral devices like disk drives and printers.
Some in style OSs embody UNIX operative System, Windows OS, VMS, OS/400, AIX, z/OS, etc.
Definition
An OS could be a program that acts as associate degree interface between the user and therefore the hardware and controls the execution of every kind of programs.
Fig 1 – Operating system
Following are a number of necessary functions of associate degree OS.
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detection aids
• Coordination between different software package and users
Memory Management
Memory management refers to management of Primary Memory or Main Memory. Main memory could be a massive array of words or computer memory units wherever every word or byte has its own address.
Main memory provides a quick storage that may be accessed directly by the C.P.U. For a program to be dead, it should within the main memory. Associate degree OS will the subsequent activities for memory management −
● Keeps tracks of primary memory, i.e., what a part of it are in use by whom, what half aren't in use.
● In concurrent execution, the OS decides that method can get memory once and the way abundant.
● Allocates the memory once a method requests it to try and do thus.
● De-allocates the memory once a method now not wants it or has been terminated.
Processor Management
In concurrent execution setting, the OS decides that method gets the processor once and for the way abundant time. This perform is termed method planning. Associate degree OS will the subsequent activities for processor management −
● Keeps tracks of method or and standing of process. The program liable for this task is understood as traffic controller.
● Allocates the method or (CPU) to a process.
● De-allocates method or once a process is not any longer needed.
● Device Management
● An OS manages device communication via their several drivers. It will the subsequent activities for device management −
● Keeps tracks of all devices. Program liable for this task is understood because the I/O controller.
● Decides that method gets the device once and for the way abundant time.
● Allocates the device within the economical approach.
● De-allocates devices.
File Management
A classification system is generally organized into directories for straightforward navigation and usage. These directories could contain files and different directions.
An OS will the subsequent activities for file management −
● Keeps track of knowledge, location, uses, status etc. The collective facilities are usually called classification system.
● Decides United Nations agency gets the resources.
● Allocates the resources.
● De-allocates the resources.
● Other necessary Activities
● Following are a number of the necessary activities that associate degree OS
● Security − By means that of arcanum and similar different techniques, it prevents unauthorized access to programs and knowledge.
● Control over system performance − Recording delays between request for a service and response from the system.
● Job accounting − Keeping track of your time and resources employed by varied jobs and users.
● Error detection aids − Production of dumps, traces, error messages, and different debugging and error detection aids.
● Coordination between different software’s and users − Coordination and assignment of compilers, interpreters, assemblers and different software package to the varied users of the pc systems.
Q2) Write the types of operating system?
A2) Operating systems area unit there from the terribly 1st pc generation and that they keep evolving with time. During this chapter, we will discuss a number of the vital varieties of in operation systems that are most ordinarily used.
Batch software system
The users of a batch software system don't act with the pc directly. Every user prepares his job on associate degree off-line device like punch cards and submits it to the pc operator. To hurry up process, jobs with similar wants area unit batched along and run as a bunch. The programmers leave their programs with the operator and therefore the operator then kinds the programs with similar needs into batches.
The problems with Batch Systems area unit as follows –
● Lack of interaction between the user and therefore the job.
● CPU is usually idle, as a result of the speed of the mechanical I/O devices is slower than the mainframe.
● Difficult to supply the required priority.
Time-sharing in operating systems
Time-sharing could be a technique that permits many of us, settled at varied terminals, to use a specific system at identical time. Time-sharing or multitasking could be a logical extension of execution. Processor's time that is shared among multiple users at the same time is termed as time-sharing.
The main distinction between Multiprogrammed Batch Systems and Time-Sharing Systems is that just in case of Multiprogrammed batch systems, the target is to maximize processor use, whereas in Time-Sharing Systems, the target is to attenuate latency.
Multiple jobs area unit dead by the mainframe by change between them, however the switches occur thus oftentimes. Thus, the user will receive a right away response. For instance, in an exceedingly dealings process, the processor executes every user program in an exceedingly short burst or quantum of computation. That is, if n users area unit gift, then every user will get a time quantum. Once the user submits the command, the latency is in few seconds at the most.
The software system uses mainframe programing and execution to supply every user with a tiny low portion of a time. Pc systems that were designed primarily as batch systems are changed to time-sharing systems.
Advantages of Timesharing in operation systems area unit as follows –
● Provides the advantage of fast response.
● Avoids duplication of code.
● Reduces mainframe idle time.
Disadvantages of Time-sharing in operation systems area unit as follows –
● Problem of responsibility.
● Question of security and integrity of user programs and information.
● Problem of information communication.
Distributed software system
Distributed systems use multiple central processors to serve multiple time period applications and multiple users. Processing jobs area unit distributed among the processors consequently.
The processors communicate with each other through varied communication lines (such as high-speed buses or phone lines). These area unit referred as loosely coupled systems or distributed systems. Processors in an exceedingly distributed system could vary in size and performance. These processors area unit referred as sites, nodes, computers, and so on.
The advantages of distributed systems area unit as follows –
● With resource sharing facility, a user at one website could also be ready to use the resources on the market at another.
● Speedup the exchange of information with each other via electronic message.
● If one website fails in an exceedingly distributed system, the remaining sites will doubtless continue in operation.
● Better service to the shoppers.
● Reduction of the load on the host pc.
● Reduction of delays in processing.
Network software system
A Network software system runs on a server and provides the server the potential to manage information, users, groups, security, applications, and different networking functions. The first purpose of the network software system is to permit shared file and printer access among multiple computers in an exceedingly network, generally an {area|a neighborhood} area network (LAN), a non-public network or to different networks.
Examples of network in operation systems embody Microsoft Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.
The advantages of network in operation systems area unit as follows –
● Centralized server’s area unit extremely stable.
● Security is server managed.
● Upgrades to new technologies and hardware is simply integrated into the system.
● Remote access to servers is feasible from completely different locations and kinds of systems.
The disadvantages of network in operation systems area unit as follows –
● High price of shopping for and running a server.
● Dependency on a central location for many operations.
● Regular maintenance and updates area unit needed.
Real Time software system
A time period system is outlined as a knowledge process system during which the interval needed to method and answer inputs is thus little that it controls the atmosphere. The time taken by the system to reply to associate degree input and show of needed updated info is termed because the latency. Thus, during this methodology, the latency is extremely less as compared to on-line process.
Real-time systems area unit used once the area unit rigid time needs on the operation of a processor or the flow of information and time period systems is used as an impact device in an exceedingly dedicated application. A time period software system should have well-defined, mounted time constraints, otherwise the system can fail. For instance, Scientific experiments, medical imaging systems, industrial management systems, weapon systems, robots, traffic management systems, etc.
The area unit 2 varieties of time period in operation systems.
Hard time period systems
Hard time period systems guarantee that essential tasks complete on time. In onerous time period systems, external storage is restricted or missing and therefore the information is kept in storage. In these systems, computer storage is sort of ne'er found.
Soft real-time systems
Soft real-time systems are less restrictive. A critical real-time task gets priority over other tasks and retains the priority until it completes. Soft real-time systems have limited utility than hard real-time systems. For example, multimedia, virtual reality, Advanced Scientific Projects likes undersea exploration and planetary rovers, etc.
Q3) Explain the function of the operating system?
A3) In an operating system software plays out every one of the following functions:
- Process management: process management causes the os to create and delete processes. It likewise gives mechanisms for synchronization and communication among processes.
- Memory management: memory management module plays out the role of assignment and de-allotment of memory space to programs needing the resources.
- File management: it deals with all the file-related tasks, for example, storage organization, recovery, naming, sharing, and protection of files.
- Device management: device management keeps track of all the devices. This module is in charge of the task also known as the i/o controller. It additionally plays out the undertaking of designation and de-distribution of the devices.
- I/o system management: one of the primary objects of any os is to conceal the identity of that hardware device from the user.
- Secondary-storage management: systems have a few degrees of storage which incorporates primary storage, secondary storage, and cache storage. Instructions and data must be put away in primary storage or cache so a running program can reference them.
- Security: security module ensures the data and information of a computer system against malware danger and authorized access.
- Command interpretation: this module is interpreting directions given by the acting system and assigns resources to process those directions.
- Networking: a distributed system is a collection of processors that don't share a memory, hardware devices, or a clock. The processors speak with each other through the network.
- Job accounting: keeping track of time and resources utilized by different jobs and users.
- Communication management: manage the coordination and task of compilers, interpreters, and other software resources of the different users of the computer systems.
Q4) What do you mean by abstract view of OS?
A4) The process operating system as User Interface:
● User
● System and application programs
● Operating system
● Hardware
Fig 2: Abstract view of components of computer system
To run other applications, every computer must have an operating system. The operating system manages how the hardware is used by the many system and application applications for different users. It just creates a setting in which other applications can perform beneficial tasks.
The operating system is a collection of applications that run on a computer and allow it to function effectively. It does things like recognize keyboard input, maintain track of files and folders on the hard drive, deliver output to the display screen, and operate peripheral devices.
OS was created with two primary goals in mind:
1. It manages the distribution and utilization of the computing system's resources among users and workloads.
2. It creates a bridge between the computer hardware and the programmer, making coding, creation, and debugging of application programs easier and more feasible.
Assembler - An assembly language program is fed into an assembler. The loader receives an object program as well as information that allows it to prepare the object program for execution. At one time, a computer programmer had access to a rudimentary machine that translated some fundamental instructions into hardware. He'd program this computer by writing a series of ones and zeros (machine language) and storing them in the machine's memory.
Compilers - Compilers and interpreters deal with high-level languages such as FORTRAN, COBOL, ALGOL, and PL/I. A compiler is a program that takes a source program written in a "high-level language" and generates an object program from it. An interpreter is a program that simulates machine language execution of a source program. Both a compiler and its related language are frequently referred to by the same name (FORTRAN, COBOL, etc.).
Loader - A Loader is a routine that loads and prepares an object program for execution. Loading techniques include absolute, relocated, and direct-linking. The loader must load, move, and link the object program in general. The loader is a program that loads and prepares programs for execution in memory. In a simple loading scheme, the assembler produces a program's machine language translation to a secondary device, which is then loaded into the core by a loader. The loader loads the machine language version of the user's software into memory and hands control over to it. Because the loader program is substantially smaller than the assembler, the user's program has more core available.
Q5) Define system structure?
A5) The software may be a construct that enables the user application programs to act with the system hardware. Since the software is such a fancy structure, it ought to be created with utmost care therefore it will be used and changed simply. A simple thanks to doing that is to form the software in elements. Every one of those elements ought to be outlined with clear inputs, outputs, and functions.
Simple structure
There square measure several operative systems that have a rather easy structure. These started as little systems and quickly distended a lot more than their scope. A typical example of this can be ms-dos. It had been designed merely for a distinct segment quantity for individuals. There was no indication that it might become therefore well-liked.
An image as an instance of the structure of ms-dos is as follows −
Fig 3 – MS-DOS structure
It is higher than operative systems have a standard structure, in contrast to ms-dos. That may cause larger management over the pc system and its numerous applications. The standard structure would conjointly permit the programmers to cover data pro re nata and implement internal routines as they see work while not ever-changing the outer specifications.
Layered structure
One way to realize modularity within the software is that the stratified approach. In this, the rock bottom layer is that the hardware, and therefore the top layer is that the interface.
An image demonstrating the stratified approach is as follows −
Fig 4 – The layered structure of OS
As seen from the image, every higher layer is made on the rock bottom layer. All the layers hide some structures, operations, etc. from their higher layers.
One downside with the stratified structure is that every layer has to be rigorously defined. This is often necessary as a result of the higher layers can solely use the functionalities of the layers below them.
Q6) Write short notes on system calls?
A6) The interface between a process and an operating system is provided by system calls. In general, system calls are available as assembly language instructions. They are also included in the manuals used by the assembly level programmers. System calls are usually made when a process in user mode requires access to a resource. Then it requests the kernel to provide the resource via a system call.
A figure representing the execution of the system call is given as follows −
Fig 5 - The execution of the system call
As can be seen from this diagram, the processes execute normally in the user mode until a system call interrupts this. Then the system call is executed on a priority basis in the kernel mode. After the execution of the system call, the control returns to the user mode and execution of user processes can be resumed.
In general, system calls are required in the following situations −
● If a file system requires the creation or deletion of files. Reading and writing from files also require a system call.
● Creation and management of new processes.
● Network connections also require system calls. This includes sending and receiving packets.
● Access to a hardware device such as a printer, scanner etc. requires a system call.
Q7) Explain Types of System Calls?
A7) There are mainly five types of system calls. These are explained in detail as follows −
Process Control
These system calls deal with processes such as process creation, process termination etc.
File Management
These system calls are responsible for file manipulation such as creating a file, reading a file, writing into a file etc.
Device Management
These system calls are responsible for device manipulation such as reading from device buffers, writing into device buffers etc.
Information Maintenance
These system calls handle information and its transfer between the operating system and the user program.
Communication
These system calls are useful for interprocess communication. They also deal with creating and deleting a communication connection.
Some of the examples of all the above types of system calls in Windows and Unix are given as follows −
Types of System Calls | Windows | Linux |
Process Control | CreateProcess() ExitProcess() WaitForSingleObject() | Fork() Exit() Wait() |
File Management | CreateFile() ReadFile() WriteFile() CloseHandle() | Open() Read() Write() Close() |
Device Management | SetConsoleMode() ReadConsole() WriteConsole() | Ioctl() Read() Write() |
Information Maintenance | GetCurrentProcessID() SetTimer() Sleep() | Getpid() Alarm() Sleep() |
Communication | CreatePipe() CreateFileMapping() MapViewOfFile() | Pipe() Shmget() Mmap() |
There are many different systems calls as shown above. Details of some of those system calls are as follows −
Open()
The open() system call is used to provide access to a file in a file system. This system call allocates resources to the file and provides a handle that the process uses to refer to the file. A file can be opened by multiple processes at the same time or be restricted to one process. It all depends on the file organization and file system.
Read()
The read() system call is used to access data from a file that is stored in the file system. The file to read can be identified by its file descriptor and it should be opened using open() before it can be read. In general, the read() system calls takes three arguments i.e. the file descriptor, buffer which stores read data and number of bytes to be read from the file.
Write()
The write() system calls writes the data from a user buffer into a device such as a file. This system call is one of the ways to output data from a program. In general, the write system calls take three arguments i.e., file descriptor, pointer to the buffer where data is stored and number of bytes to write from the buffer.
Close()
The close() system call is used to terminate access to a file system. Using this system call means that the file is no longer required by the program and so the buffers are flushed, the file metadata is updated and the file resources are de-allocated.
Q8) Explain virtual machines?
A8) Virtual Machine abstracts the hardware of our pc like computer hardware, disk drives, memory, NIC (Network Interface Card) etc., into many various execution environments as per our needs, therefore giving U.S. a feel that every execution surroundings could be a single laptop. For instance, VirtualBox.
When we run totally different processes on AN package, it creates AN illusion that every method is running on a distinct processor having its own memory board, with the assistance of computer hardware programming and virtual-memory techniques. There square measure extra options of a method that can't be provided by the hardware alone like system calls and a filing system. The virtual machine approach doesn't offer these extra functionalities however it solely provides AN interface that's same as basic hardware. Every method is given a virtual copy of the underlying ADPS.
We can produce a virtual machine for many reasons, all of that square measure essentially associated with the power to share a similar basic hardware nevertheless may also support totally different execution environments, i.e., totally different operational systems at the same time.
The main downside with the virtual-machine approach involves disk systems. Allow us to suppose that the physical machine has solely 3 disk drives however needs to support seven virtual machines. Obviously, it cannot portion a drive to every virtual machine, as a result of virtual-machine software package itself can want substantial space to produce memory board and spooling. The answer is to produce virtual disks.
Users square measure so given their own virtual machines. Once that they will run any of the operational systems or software package packages that square measure out there on the underlying machine. The virtual-machine software package worries with multiprogramming multiple virtual machines onto a physical machine, however it doesn't get to take into account any user-support software package. This arrangement will offer a helpful thanks to divide the matter of planning a multi-user interactive system, into 2 smaller items.
Q9) Write the advantages and disadvantages of virtual machines?
A9) Advantages:
- There aren't any protection issues as a result of every virtual machine is totally isolated from all alternative virtual machines.
- Virtual machine will offer AN instruction set design that differs from real computers.
- Simple maintenance, availableness and convenient recovery.
Disadvantages:
- Once multiple virtual machines square measure at the same time running on a bunch laptop, one virtual machine is often stricken by alternative running virtual machines, reckoning on the employment.
- Virtual machines aren't as economical as a true one once accessing the hardware.
Q10) Describe the process?
A10) A process is basically a program in execution. The execution of a process must progress in a sequential fashion.
A process is defined as an entity which represents the basic unit of work to be implemented in the system.
To put it in simple terms, we write our computer programs in a text file and when we execute this program, it becomes a process which performs all the tasks mentioned in the program.
When a program is loaded into the memory and it becomes a process, it can be divided into four sections ─ stack, heap, text and data. The following image shows a simplified layout of a process inside main memory −
Fig 6 - A simplified layout of a process inside main memory
S.N. | Component & Description |
1 | Stack The process Stack contains the temporary data such as method/function parameters, return address and local variables. |
2 | Heap This is dynamically allocated memory to a process during its run time. |
3 | Text This includes the current activity represented by the value of Program Counter and the contents of the processor's registers. |
4 | Data This section contains the global and static variables. |
Program
A program is a piece of code which may be a single line or millions of lines. A computer program is usually written by a computer programmer in a programming language. For example, here is a simple program written in C programming language −
#include <stdio.h>
Int main() {
Printf("Hello, World! \n");
Return 0;
}
A computer program is a collection of instructions that performs a specific task when executed by a computer. When we compare a program with a process, we can conclude that a process is a dynamic instance of a computer program.
A part of a computer program that performs a well-defined task is known as an algorithm. A collection of computer programs, libraries and related data are referred to as software.
Q11) Define process life cycle?
A11) When a process executes, it passes through different states. These stages may differ in different operating systems, and the names of these states are also not standardized.
In general, a process can have one of the following five states at a time.
S.N. | State & Description |
1 | Start This is the initial state when a process is first started/created. |
2 | Ready The process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. Process may come into this state after Start state or while running it by but interrupted by the scheduler to assign CPU to some other process. |
3 | Running Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor executes its instructions. |
4 | Waiting Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input, or waiting for a file to become available. |
5 | Terminated or Exit Once the process finishes its execution, or it is terminated by the operating system, it is moved to the terminated state where it waits to be removed from main memory. |
Fig 7 – Process state
Q12) What is PCB?
A12) A Process Control Block is a data structure maintained by the Operating System for every process. The PCB is identified by an integer process ID (PID). A PCB keeps all the information needed to keep track of a process as listed below in the table −
S.N. | Information & Description |
1 | Process State The current state of the process i.e., whether it is ready, running, waiting, or whatever. |
2 | Process privileges This is required to allow/disallow access to system resources. |
3 | Process ID Unique identification for each of the process in the operating system. |
4 | Pointer A pointer to parent process. |
5 | Program Counter Program Counter is a pointer to the address of the next instruction to be executed for this process. |
6 | CPU registers Various CPU registers where process need to be stored for execution for running state. |
7 | CPU Scheduling Information Process priority and other scheduling information which is required to schedule the process. |
8 | Memory management information This includes the information of page table, memory limits, Segment table depending on memory used by the operating system. |
9 | Accounting information This includes the amount of CPU used for process execution, time limits, execution ID etc. |
10 | IO status information This includes a list of I/O devices allocated to the process. |
The architecture of a PCB is completely dependent on Operating System and may contain different information in different operating systems. Here is a simplified diagram of a PCB −
Fig 8 - PCB
The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates.
Q13) Explain threads?
A13) There is the way of thread execution within the method of any software. With the exception of this, there may be quite one thread within a method. Thread is usually cited as a light-weight method.
The process may be reduction into such a big amount of threads. For instance, in an exceedingly browser, several tabs may be viewed as threads. MS Word uses several threads - data format text from one thread, process input from another thread, etc.
Types of Threads
In the software, there square measure 2 sorts of threads.
- Kernel level thread.
- User-level thread.
User-level thread
The software doesn't acknowledge the user-level thread. User threads may be simply enforced and it's enforced by the user. If a user performs a user-level thread obstruction operation, the complete method is blocked. The kernel level thread doesn't unskilled person regarding the user level thread. The kernel-level thread manages user-level threads as if they're single-threaded processes? Examples: Java thread, POSIX threads, etc.
Advantages of User-level threads
- The user threads may be simply enforced than the kernel thread.
- User-level threads may be applied to such sorts of in operation systems that don't support threads at the kernel-level.
- It's quicker and economical.
- Context switch time is shorter than the kernel-level threads.
- It doesn't need modifications of the software.
- User-level threads illustration is extremely easy. The register, PC, stack, and mini thread management blocks square measure hold on within the address house of the user-level method.
- It's easy to form, switch, and synchronize threads while not the intervention of the method.
Disadvantages of User-level threads
- User-level threads lack coordination between the thread and therefore the kernel.
- If a thread causes a page fault, the whole method is blocked.
Kernel level thread
The kernel thread acknowledges the software. There square measure a thread management block and method management block within the system for every thread and method within the kernel-level thread. The kernel-level thread is enforced by the software. The kernel is aware of regarding all the threads and manages them. The kernel-level thread offers a supervisor call instruction to form and manage the threads from user-space. The implementation of kernel threads is troublesome than the user thread. Context switch time is longer within the kernel thread. If a kernel thread performs an obstruction operation, the Banky thread execution will continue. Example: Window Solaris.
Advantages of Kernel-level threads
- Kernel can schedule many threads from the same process on numerous processes at the same time.
- If a process's main thread is stalled, the Kernel can schedule another process's main thread.
- Kernel routines can be multithreaded as well.
Disadvantages of Kernel-level threads
- Kernel threads are more difficult to establish and maintain than user threads.
- A mode switch to the Kernel is required to transfer control from one thread to another within the same process.
Components of Threads
Any thread has the subsequent parts.
- Program counter
- Register set
- Stack house
Q14) What are the benefits of threads?
A14) Benefits of Threads
● Enhanced outturn of the system: once the method is split into several threads, and every thread is treated as employment, the quantity of jobs worn out the unit time will increase. That's why the outturn of the system additionally will increase.
● Effective Utilization of digital computer system: after you have quite one thread in one method, you'll be able to schedule quite one thread in additional than one processor.
● Faster context switch: The context shift amount between threads is a smaller amount than the method context shift. The method context switch suggests that additional overhead for the hardware.
● Responsiveness: once the method is split into many threads, and once a thread completes its execution, that method may be suffered as before long as doable.
● Communication: Multiple-thread communication is easy as a result of the threads share an equivalent address house, whereas in method, we have a tendency to adopt simply some exclusive communication methods for communication between 2 processes.
● Resource sharing: Resources may be shared between all threads at intervals a method, like code, data, and files. Note: The stack and register can't be shared between threads. There square measure a stack and register for every thread.
Q15) Explain thread state diagram?
A15) Thread State Diagram
Appearing on your screen may be a thread state diagram. Let's take a more in-depth explore the various states showing on the diagram.
Fig 9 - OS Thread State Diagram
A thread is within the new state once it's been created. It does not take any hardware resources till it's really running. Now, the method is taking on hardware resources as a result of it's able to run. However, it's in an exceedingly runnable state as a result of it might be looking forward to another thread to run and then it's to attend for its flip.
A thread that isn't allowed to continue remains in an exceedingly blocked state. Parenthetically that a thread is looking forward to input/output (I/O), however it ne'er gets those resources, therefore it'll stay in an exceedingly blocked state. The great news is that a blocked thread will not use hardware resources. The thread is not stopped forever. For instance, if you permit emergency vehicles to pass, it doesn't mean that you just square measure forever barred from your final destination. Similarly, those threads (emergency vehicles) that have the next priority square measure processed prior to you. If a thread becomes blocked, another thread moves to the front of the road. However, this is often accomplished is roofed within the next section regarding programming and context shift.
Finally, a thread is terminated if it finishes a task with success or abnormally. At this time, no hardware resources square measure used.
Q16) Describe multithreading?
A16) Multithreading Models
Some operating system provides a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models are three types
● Many to many relationship.
● Many to one relationship.
● One to one relationship.
Many to Many Model
The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads.
The following diagram shows the many-to-many threading model where 6 user level threads are multiplexing with 6 kernel level threads. In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallel on a multiprocessor machine. This model provides the best accuracy on concurrency and when a thread performs a blocking system call, the kernel can schedule another thread for execution.
Fig 10 - The best accuracy on concurrency
Many to One Model
Many-to-one model maps many users level threads to one Kernel-level thread. Thread management is done in user space by the thread library. When thread makes a blocking system call, the entire process will be blocked. Only one thread can access the Kernel at a time, so multiple threads are unable to run in parallel on multiprocessors.
If the user-level thread libraries are implemented in the operating system in such a way that the system does not support them, then the Kernel threads use the many-to-one relationship modes.
Fig 11 – Many to one model
One to One Model
There is one-to-one relationship of user-level thread to the kernel-level thread. This model provides more concurrency than the many-to-one model. It also allows another thread to run when a thread makes a blocking system call. It supports multiple threads to execute in parallel on microprocessors.
Disadvantage of this model is that creating user thread requires the corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one relationship model.
Fig 12 – One to one model
Q17) Write the difference between user level and kernel level thread?
A17) Difference between User-Level & Kernel-Level Thread
S.N. | User-Level Threads | Kernel-Level Thread |
1 | User-level threads are faster to create and manage. | Kernel-level threads are slower to create and manage. |
2 | Implementation is by a thread library at the user level. | Operating system supports creation of Kernel threads. |
3 | User-level thread is generic and can run on any operating system. | Kernel-level thread is specific to the operating system. |
4 | Multi-threaded applications cannot take advantage of multiprocessing. | Kernel routines themselves can be multithreaded. |