Operating System

An operating system is a program that manages the computers’ hardware. It provides a basis for application program and acts as an intermediary between the computer user
and computer hardware. The operating system controls and coordinates the use of the hardware among the various
application program for the various user.

Components of computer system

A computer system can be divided roughly into four components:

  1. the hardware,
  2. the operating system,
  3. the application program, and
  4. the user.

The hardware—the central processing unit (CPU), the
memory, and the input/output (I/O) devices—provides the
basic computing resources for the system.

The application programs – such as word processors,
spreadsheets, compilers, and Web browsers – define the
ways in which these resources are used to solve users’
computing problems.

The operating system controls the hardware and coordinates its use among the various application programs for the various users.

Different Viewpoints of Operating System

User View Point

From the user perspective, the goal is to maximize the work that the user is performing. In this
case, the OS is designed for ease of use, with some attention paid to performance and security
and non-paid to resource utilization (how various hardware and software are shared).

System View Point

From the computer’s point of view, the OS is the program most intimately involved with the
hardware. We can view an OS as a resource allocator. A computer system has many resources that may be required to solve a problem such as CPU time, memory space, file storage space, I/O devices, and so on. The OS acts as the manager of these resources. A slightly different view of an operating system emphasizes the need to control the various I/O devices and user programs. An operating system is a control program. A control program manages
the execution of user programs to prevent errors and improper use of the computer. It is
especially concerned with the operation and control of I/O devices.

Computer System Architecture


The computer system can be organized in a number of different ways, which we can categorize roughly according to the number of general-purpose processors used.

Single-Processor system

On a single processor system, there is one main CPU capable of executing a general-purpose instruction set, including instructions from user processes. Almost all single processor systems have other special-purpose processors as well. They may come in the form of
device-specific processors, such as disk, keyboard, and graphics controllers; or, on mainframes, they may come in the form of more general-purpose processors, such as I/O processors that move data rapidly among the components of the system.

Multiprocessor System

Multiprocessor system is also known as parallel system or multicore system or tightly coupled system. Such system has two or more processors in close communication, sharing
the computer bus and sometimes the clock, memory, and peripheral devices.

Advantages of multiprocessor system

Increased Throughput: By increasing the no. of processor, we expect to get more work done
in less time. The speed – up ratio with N processor is not N, however; rather, it is less than N.
When multiple processors co-operate on a task, a certain amount of overhead is incurred in keeping all the parts working correctly.
Economy of Scale: Multiprocessor system can cost less than equivalent multiple singleprocessor system, because they can share peripherals, mass storage, and power supplies. If
several programs operate on the same set of data, it is cheaper to store those data on one
disk and to have all the processors share them than to have many computers with local disks and many copies of the data.
Increased Reliability: If function can be distributed properly among several processors, then
the failure of one processor will not halt the system, only slow it down. If we have ten processors and one fails, then each of the remaining nine processors can pick up a share of work of the failed processor. Thus, the entire system runs only 10% slower, rather than failing altogether.

Multiprogramming

An OS provides the environment within which programs are executed. One of the important
aspect of OS is the ability to multi-program. A single-program cannot, in general keep either the CPU or the I/O devices busy all the times. Multiprogramming increase CPU utilization by organizing jobs (code or data) so that the CPU always has one to execute. The idea behind the multiprogramming is that the OS keeps several jobs in memory
simultaneously. The OS picks and begins to execute one of the jobs in memory. Eventually the jobs
may have to wait for some task, such as an I/O operation to complete. In a non-multiprogramming system, the CPU would sit idle. In multiprogramming system, the OS Simply switches to and execute another jobs. When that job needs to wait the CPU switches to another jobs and so on. Eventually the 1st job finishes waiting and gets the CPU back. As long as at least one job needs to execute, the CPU is never idle

Operating System Services

Following are the function/services provided by the OS from the user perspective:


1.User Interface
Almost all OS have a user interface (UI). This interface can take several forms. One is a
command – line interface (CLI), which uses text command and a method for entering them.
Another is a Batch interface, in which commands and directives to control those commands
are entered into a files, and those files are executed. Most commonly, a Graphical User
Interface (GUI) is used. Here, the interface is a window system with a pointing device to
direct I/O, choose from menus and make selection and a keyboard to enter text.

2.Program Execution


The system must be able to load a program into memory and run that program. The program
must be able to end its execution, either normally or abnormally (indicating error).

3.I/O Operation

A running program may require I/O, which may involve a file or a I/O devices. For efficiency
and protection, user usually cannot control I/O devices directly. Therefore, O/s must provide a mean to do I/O.

File System Manipulation
A process need to read and write files and directories. They also need to create and delete
them by name, searches for a given file, and list file information. Finally, some OS include
permission management to allow or deny access to file or directories based on file
ownership.
5.Communication
There are many circumstances in which one process needs to exchange information with
another process. Such communication may occur between process that are executing one
same computer or between processes that are executing on different computer system tied
together by a computer network. Communication may be implemented by a shared
memory, in which two or more processes read and write to share section of memory, or
message passing, in which packets of information is predefined formats are moved between
process by OS.

4.Error Detecting

For each types of error, the OS should take the appropriate action to ensure correct and
consisting computing.
Another set of OS function includes from the system perspective

5.Resource Allocation

When there are multiple user or multiple jobs running at the same time, resource must be
allocated to each of them. The OS manages many different types of resource.

6.Accounting

We want to keep track of which user use how much and what kind of computer resource.
This record keeping may be used for accounting.

7.Protection and Security

The owner information stored in multiuser or networked computer system may want to
control use of that information. Protection involves ensuring that all access to the system
resource is controlled. Security of the system from outsiders is also important. Such Security
start with requiring each user to authenticate themselves to the system, usually by means of
a password, to gain access to system resource.

Computer System Operation

For a computer to start running—for instance, when it is powered up or rebooted—it needs to have an initial program to run. This initial program, or bootstrap program, tends to be simple. Typically, it is stored within the computer hardware in read-only memory (ROM) or electrically erasable programmable read-only memory (EEPROM), known by the general term firmware. It
initializes all aspects of the system, from CPU registers to device controllers to memory contents. The bootstrap program must know how to load the operating system and how to start executing that system. To accomplish this goal, the bootstrap program must locate the operating – system
kernel and load it into memory. Kernel is a program at the core of a computer’s operating system
that act as an intermediate between software and hardware and control almost every single
operation.Process Any program which is in execution state is known as process. A process will need certain resources, such as CPU time, memory, files, and I/O devices to accomplish its task. These resources are allocated to the process either when it is created or while it is executing. The OS helps us to create, schedule, and terminates the processes which is used by CPU. A process created by the main process is called a child process.
Process Architecture Stack: The Stack stores temporary data like function parameters, returns addresses, and local variables.
Heap Allocates memory, which may be processed during its run time.
Data: It contains the variable.
Text: Text Section includes the current activity, which is represented by the value of
the Program Counter. Process State A process state is a condition of the process at a specific instant of time. It also defines the current position of the process. A process may be in one of the
following states:

  1. New: The new process is created when a specific program
    calls from secondary memory i.e. hard disk to primary memory
    RAM.
  2. Ready: In a ready state, the process should be loaded into
    the primary memory, which is ready for execution.
  3. Waiting: The process is waiting for the allocation of CPU
    time and other resources for execution.
  4. Running: The process is an execution state.
  5. Terminated: Terminated state specifies the time when a process is terminated or ended.

*6. Blocked: It is a time interval when a process is waiting for an event like I/O operations to
complete.
*7. Suspended: Suspended state defines the time when a process is ready for execution but has
not been placed in the ready queue by OS.

Process Control Block
The PCB stands for Process Control Block also called Task Control Block. It is a data structure that is maintained by the Operating System for every process. The PCB should be identified by an integer Process ID (PID). It helps us to store all the information required to keep track of all the running processes. It is also accountable for storing the contents of processor registers. These are saved when the process moves from the running state and then returns back to it. The information is quickly updated in the PCB by the OS as soon as the process makes the state transition. A PCB keeps all the information needed to keep track of a process as listed below:
Process State: The current state of the process that may be new, ready, running, waiting, halted,
and so on.
Program Counter: The counter indicates the address of the next instruction to be executed for this process.
CPU register: Various CPU registers where process need to be stored for execution for running state.
CPU-Scheduling Information: This information includes a process priority, pointer
to scheduling queues, and any other scheduling parameters.
Memory Management Information: This information may include such items as
the value of the base and limits registers and the page tables, or the segment tables, depending on the memory system used by the operating system.
Accounting Information: This information includes the amount of CPU used for process execution, time limits, account numbers, job or process
numbers, etc.
I/O Status Information: This information include the list of I/O devices allocated to the process, a list of opens files, and so on.

Process Scheduling
The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular strategy. Process scheduling is an essential part of a Multiprogramming operating systems. Such operating systems allow more than one process to be loaded into the executable memory at a time and the loaded process shares the CPU using time multiplexing. Process Scheduling Queues The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a separate queue for each of the process states and PCBs of all processes in the same execution state are placed in the same queue. When the state of a process is changed, its PCB is unlinked from its current queue and moved to its new state queue.

The Operating System maintains the following important process scheduling queues:
Job Queue: This is a queue which keeps all the process in the system.
Ready Queue: This queue keeps a set of all processes residing in main memory, ready and waiting
to execute. A new process is always put in this queue.
Device Queue: The processes which are blocked due to unavailability of an I/O device constitute this queue.

Each rectangular box represents a queue. Job queue, ready queue and a set of device queues. The
circles represent the resources that serve the queues, and the arrows indicate the flow of
processes in the system.
A new process is initially put in the ready queue. It waits there until it is selected for execution, or dispatched. Once the process is allocated the CPU and is executing, one of several events could occur:

  1. The process could issue an I/O request an then be placed in an I/O queue.
  2. The Process could create a new child process and wit for the child’s terminated.
  3. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back
    in the ready queue. In the first two cases, the process eventually switches from the waiting state to the ready state and is then put back in the ready queue. A process continues this cycle until it terminates, at which
    time it is removed from all queues and has its PCB and resources deallocated.
    Scheduler Schedulers are special system software which handle process scheduling in various ways. Their main task is to select the jobs to be submitted into the system and to decide which process to run.
    Schedulers are of three types:
  4. Long Term Scheduler: It is also called a job scheduler. A long-term scheduler determines which
    programs are admitted to the system for processing. It selects processes from the secondary memory and loads them into memory for execution. Process loads into the memory for CPU
    scheduling.
  5. Short Term Scheduler: It is also called as CPU scheduler. Its main objective is to increase system performance in accordance with the chosen set of criteria. It is the change of ready state to running state of the process. Short-term schedulers, also known as dispatchers, make the decision of which process to execute next. Short-term schedulers are faster than long-term schedulers.
  6. Medium Term Scheduler: Medium-term scheduling is a part of swapping. It removes the processes from the memory. It reduces the degree of multiprogramming. The medium-term

scheduler is in-charge of handling the swapped out-processes. A running process may become suspended if it makes an I/O request. A suspended process cannot make any progress towards completion. In this condition, to remove the process from memory and make space for other processes, the suspended process is moved to the secondary storage. This process is called swapping, and the process is said to be swapped out or rolled out.

Context Switch
A context switch is the mechanism to store and restore the state or context of a CPU in Process Control block so that a process execution can be resumed from the same point at a later time. Using this technique, a context switcher enables multiple processes to share a single CPU. Context switching is an essential part of a multitasking operating system features.

CPU Scheduling

CPU Scheduling is a process of determining which process will own CPU for execution while
another process is on hold. The main task of CPU scheduling is to make sure that whenever the
CPU remains idle, the OS at least select one of the processes available in the ready queue for
execution. The selection process will be carried out by the CPU scheduler. It selects one of the
processes in memory that are ready for execution.

Types of CPU Scheduling

Preemptive Scheduling

In Preemptive Scheduling, the tasks are mostly assigned with their priorities. Sometimes it is important to run a task with a higher priority before another lower priority task, even if the lower priority task is still running. The lower priority task holds for some time and resumes when the higher priority task finishes its execution.

Non-Preemptive Scheduling

In this type of scheduling method, the CPU has been allocated to a specific process. The process that keeps the CPU busy will release the CPU either by switching context or terminating. It is the only method that can be used for various hardware platforms. That’s because it doesn’t need special hardware (for example, a timer) like preemptive scheduling.
When Scheduling is Preemptive or Non Preemptive? To determine if scheduling is preemptive or non-preemptive, consider these four parameters:

A process switching from the running to the waiting state. Non-Preemptive

Specific process switches from the running state to the ready state. Preemptive

Specific process switches from the waiting state to the ready state. Preemptive

Process finished its execution and terminated. Non-Preemptive
Important CPU Scheduling Terminologies Burst Time/Execution Time: It is a time required by the process to complete execution. It’s also called running time.
Arrival Time: When a process enters in a ready state.
Finish Time: When process complete and exit from a system.
Throughput: It’s a number of process that are completed per time unit.
Waiting Time: It is the sum of the periods spent waiting in the ready queue.
Turnaround Time: It is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O. Turnaround Time = Waiting Time + Burst Time
Response Time: Response time is the time spent between the ready state and getting the CPU for the first time. Dispatcher It is a module that provides control of the CPU to the process. The Dispatcher should be fast so that it can run on every context switch. Dispatch latency is the amount of time needed by the CPU scheduler to stop one process and start another. Function performed by Dispatcher:

  • Context Switching
  • Switching to user mode

Moving to the correct location in the newly loaded program

Types of CPU Scheduling Algorithm

  1. First Come First Serve (FCFS)
  2. Shortest-Job-First (SJF)
  3. Priority Scheduling
  4. Round Robin Scheduling
    First Come First Serve (FCFS)
    First Come First Serve is the full form of FCFS. It is the easiest and simplest CPU scheduling
    algorithm. In this type of algorithm, the process which requests the CPU gets the CPU allocation
    first. This scheduling method can be managed with a FIFO queue.
    As the process enters the ready queue, its PCB (Process Control Block) is linked with the tail of the
    queue. So, when CPU becomes free, it is allocated to the process at the head of the queue. The
    running process is then removed from the queue. The code for FCFS scheduling is simple to write
    and understand.
    Characteristic of FCFS are:
  5. It offers Non-preemptive scheduling algorithm.
  6. Jobs are always executed on a first-come, first-serve policy.
  7. It is easy to implement and use.
  8. However, this method is poor in performance, and the general wait time is quite high.
    Advantages of FCFS:
  9. Simplest form of a CPU scheduling algorithm.
  10. Easy to program.
  11. Easy to use.
  12. First come first served.
    Disadvantages of FCFS:
  13. It is Non-Preemptive CPU scheduling algorithm, so after the process has been allocated to the
    CPU, it will never release the CPU until it finishes executing.
  14. The Average Waiting Time is high.
  15. Short processes that are at the back of the queue have to wait for long process at the front to
    finishes.
  16. Not an ideal technique for time-sharing system.
  17. Because of its simplicity, FCFS is not very effective.
    Example:
    Consider the following set of processes that arrives in ready queue at the time 0, with the length of
    the CPU burst given in millisecond.

Process Burst Time
P1 24
P2 3
P3 3
If the processes arrive in the order P1, P2, P3, and are server FCFS order, we get the result shown in the following Gantt Chart, which is a bar chart that illustrate a particular schedule, including the start and finish times of each of the participating processes

Thus, the average waiting time under an FCFS policy is generally not minimal and may vary
substantially if the processes’ CPU burst times vary greatly.
Shortest Job First (SJF)
Scheduling algorithm in which the process with the shortest execution time or burst time should be selected for execution next and CPU gets allotted. This scheduling method can be preemptive or non-preemptive. It significantly reduces the average waiting time for other processes awaiting execution. If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. More appropriate term for this scheduling method would be the shortest-next- CPU- burst
algorithm, because scheduling depends on the length of the next CPU burst of a process, rather than its total length or some time it is also called shortest- remaining- time- first scheduling.
Characteristic of SJF Scheduling

  1. It is associate with each job as a unit of time to complete.
  2. In this method, when the CPU is available, the next process or job with the shortest completion
    time will be executed first.
  3. It is implemented with non-preemptive policy.
  4. This algorithm method is usually for the batch-type processing, where waiting for jobs to
    complete is not critical.
  5. It improves job output by offering shorter jobs, which should be executed first, which mostly
    have a shorter turnaround time.
    Advantages of SJF Scheduling
  6. SJF is frequently used for long term scheduling.
  7. Its reduces the average waiting time over FIFO/FCFS algorithm.
  8. It gives the lowest average waiting time for a specific set of processes.
  9. It is appropriate for the jobs running in batch, where run times are known in advance.
    Disadvantages of SJF Scheduling
  10. Job completion time must be known earlier, but it is hard to predict.
  11. SJF can’t be implemented for CPU scheduling for the short term. It is because there is no specific
    method to predict the length of the upcoming CPU burst.
  12. This algorithm may cause very long turnaround time or starvation.
    Non-Preemptive Version of SJF Scheduling
    Example:
    Consider the following set of processes that arrives in ready queue at the time 0, with the length of
    the CPU burst given in millisecond.
    Process Burst Time
    P1 6
    P2 8
    P3 7
    P4 3

Using SJF scheduling, we would schedule these processes according to the following Gantt chart:

By comparison, if we were using the FCFS scheduling scheme, the average waiting time would be
10.25 milliseconds.
If two process which have same burst time then, it will follow the FCFS scheduling algorithm for
that two process. For example; here Burst time of P2 is now 3 milliseconds instead of 8
milliseconds

Process Burst Time
P1 6
P2 3
P3 7
P4 3

Preemptive Version of SJF Scheduling The SJF algorithm can be either preemptive or non-preemptive. The choice arises when a new process arrives at the ready queue while a previous process is still executing. The next CPU burst of the newly arrived process may be shorter than what is left of the currently executing process. A preemptive SJF algorithm will preempt the currently executing process, whereas a non-preemptive
SJF algorithm will allow the currently running process to finish its CPU burst.
Example:
Consider the following four processes, with the length of the CPU burst given in millisecond and with its arrival time. So, in this case processes will preempt.

Process Arrival Time Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5

Here, at time t=0 millisecond P1 arrive in ready queue and starts its execution. But after 1
millisecond P2 arrives and P1 gets preempt and its burst time reduced to 7 milliseconds. Since P2 having lower Burst Time among all other processes i.e. 4 milliseconds, will finishes its execution first, till t=5 milliseconds, because although it is SJF algorithm. Till that time all the processes get its
place in ready queue. And after P2, P4 with burst time 5 milliseconds, start its execution and terminate at t=10 millisecond. Then P1 will execute and finishes its remaining job till t=17
milliseconds. Finally, P3 finishes its execution for 9 milliseconds till t=26 milliseconds.

Priority Scheduling
Priority Scheduling is a method of scheduling processes that is based on priority. In this algorithm, the scheduler selects the tasks to work as per the priority. The processes with higher priority should be carried out first, whereas jobs with equal priorities are carried out on a round-robin or FCFS basis. Priority depends upon memory requirements, time requirements, etc. The SJF algorithm is a special case of the general priority-scheduling algorithm. In which priority (p) is the inverse of the (predicted) next CPU burst. The larger the CPU burst, the lower the priority, and vice versa. Priority scheduling can either be preemptive or non-preemptive. A major problem with this
scheduling algorithm is indefinite blocking, or starvation. A process that is ready to run but
waiting for the CPU can be considered blocked. A priority scheduling algorithm can leave some low priority processes waiting indefinitely. In a heavily loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU. Generally, one of the two things will happen. Either the process will eventually be run, or the computer system will eventually crash and lose all unfinished low-priority process.
A solution to the problem of indefinite blockage of low-priority processes is aging. Aging involves gradually increasing the priority of processes that wait in the system for a long time.

Characteristic of SJF Scheduling

  1. A CPU algorithm that schedules processes based on priority.
  2. It is used in operating system for performing batch process.
  3. It two jobs having same priority will execute on the basis of FCFS algorithm.
  4. In priority scheduling, a number is assigned to each process that indicates its priority level.
  5. Lower the number, higher the priority.
  6. It is also a preemptive scheduling, if a newer process arrives, that is having a higher priority than
    the running process, then the currently running process is preempted.
    Advantages of Priority Scheduling
  7. Easy to use scheduling method.
    14
  8. Processes are executed on the basis of priority so high priority does not need to wait for long
    which saves the time.
  9. This method provides a good mechanism where the relative important of each process may be
    precisely defined.
  10. Suitable for application with fluctuating time and resource requirements.
    Disadvantages of Priority Scheduling
  11. If the system eventually crashes, all low priority processes gets lost.
  12. If high priority process take lots of CPU time, then the lower priority processes may starve and
    will be postponed for an indefinite time.
  13. This scheduling algorithm may leave some low priority processes waiting indefinitely.
  14. A process will be blocked when it is ready to run but has to wait for the CPU because some
    other process is running currently.
    Example:
    Consider the following five processes, with the length of the CPU burst given in millisecond along
    with their priority.
    Process Priority Burst Time
    P1 3 10
    P2 1 1
    P3 4 2
    P4 5 1
    P5 2 5

Round Robin Scheduling
The name of this algorithm comes from the round-robin principle, where each person gets an equal share of something in turns. It is the oldest, simplest scheduling algorithm, which is mostly used for multitasking and time-sharing system. In Round-robin scheduling, each ready task runs turn by turn only in a cyclic queue for a limited time slice or time quantum that is generally from 10 to 100 milliseconds in length. This algorithm also offers starvation free execution of processes. It is similar to FCFS scheduling, but preemption is added to enable the system to switch between processes.
To implement RR scheduling, we again treat the ready queue as a FIFO queue of processes. New
processes are added to the tail of the ready queue. The CPU scheduler picks the first process from the ready queue, sets a timer to interrupt after 1 time-quantum, and dispatches the process. One of two things will then happen: The process may have a CPU burst of less than 1 time-quantum. In this case, the process itself will release the CPU voluntarily. The scheduler will then proceed to the next process in the ready queue. If the CPU burst of the currently running process is longer than 1 time-quantum, the timer will go
off and will cause an interrupt to the operating system. A context switch will be executed, and the
process will be put at the tail of the ready queue. The CPU scheduler will then select the next process in the ready queue.

Characteristic of Round Robin Scheduling

  1. Round robin is a preemptive algorithm
  2. The CPU is shifted to the next process after fixed interval time, which is called time
    quantum/time slice.
  3. The process that is preempted is added to the end of the queue.
  4. Time slice should be minimum, which is assigned for a specific task that needs to be processed.
    However, it may differ OS to OS.
  5. It is one of the oldest, fairest, and easiest algorithm.
    Advantages of Round Robin Scheduling
  6. It doesn’t face the issue of starvation or convoy effect.
  7. All the jobs get fair allocation of CPU.
  8. It deals with all process without any priority.
  9. This scheduling method does not depend upon burst time. That’s why it is easily implementable
    on the system.
  10. Once a process is executed for a specific set of the period, the process is preempted, and
    another process executes for that given time period.
  11. Allows OS to use the context switching method to save states of preempted processes.
  12. It gives the best performance in terms of average response time.
    Disadvantages of Round Robin Scheduling
  13. If the slicing time of computer is low, the processor output will be reduced.
  14. This method spends more time on context switching.
  15. Its performance heavily depends on time quantum.
  16. Priorities cannot be set for the processes.
  17. Lower time quantum result in higher context switching overhead in the system.
    16
    Example:
    Consider the following set of processes that arrive at time 0, with the length of the CPU burst given
    in milliseconds and time quantum is 4 milliseconds.
    Process Burst Time
    P1 24
    P2 3
    P3 3

System Call
A system call is a mechanism that provides the interface between a process and the operating
system. It is a programmatic method in which a computer program requests a service from the
kernel of the OS.
System call offers the services of the operating system to the user programs via API (Application
Programming Interface). System calls are the only entry points for the kernel system.
Example:
For example, if we need to write a program code to read data from one file, copy that data into
another file. The first information that the program requires is the name of the two files, the input
and output files. In an interactive system, this type of program execution requires some system
calls by OS:
First call is to write a prompting message on the screen.
Second, to read from the keyboard, the characters which is define the files

How System Call Works?

  1. The processes executed in the user mode till the time a system call interrupts it.
  2. After that, the system call is executed in the kernel-mode on a priority basis.
  3. Once system call execution is over, control returns to the user mode.
  4. The execution of user processes resumed in kernel mode.
    Why do we need System Call in OS?
    Following are situation which need system need system calls in OS:
  5. Reading and writing from files demand system calls.
  6. If a file system wants to create or delete files, system call are required.
  7. System calls are used for the creation and management of new processes.
  8. Network connection need system calls for sending and receiving packets.
  9. Access to hardware devices like scanner, printer, need a system call.
    Types of System Calls
  10. Process Control
    This system calls performs the task pf process creation , process termination, etc.
    Function:
    End and Abort
    Load and Execute
    Create Process and Terminate Process
    Wait and Signed Event
    Allocate and free memory
    Ex: For UNIX OS – fork(), exit(), wait()
    For Windows OS – CreateProcess(), ExitProcess(), WaitForSingleObject()
  11. File Management
    File management system calls handle file manipulation job like creating a file, reading, and
    writing, etc.
    Function:
    Create a file
    Delete fie
    Open and Close file
    Read, Write, and Reposition
    Get and set file attributes
    Ex: For UNIX OS – open(), read(), write), close()
    For Windows OS – CreateFile(), ReadFile(), WriteFile(), CloseHandle().
    FIGURE 7: TRANSITION FROM USER TO KERNEL MODE
    18
  12. Device Management
    Device management does the job of device manipulation like reading from device buffers,
    writing into device buffers, etc.
    Function:
    Request and release device
    Logically attach/detach devices
    Get and Set device attributes
    Read, Write, Reposition
    Ex: For UNIX OS – ioctl(), read(), write()
    For Windows OS – SteConsoleMode(), ReadConsole(), WriteConsole()
  13. Information Maintenance
    It handles information and its transfer between the OS and user program.
    Function:
    Get or set time and date
    Get process and
  14. attributes
    Get or set system data
    Ex: For UNIX OS – getpid(), alarm(), sleep()
    For Windows – GetCurrentProcessID(), SetTimer(), Sleep()
  15. Communication
    These types of system calls are specially used for inter-process communications.
    Function:
    Create, delete communication connection
    Send, receive message
    Help OS to transfer status information
    Attach or detach remote device
    Ex: For UNIX OS – pipe(), shm_open(), mmap()
    For Windows OS – CreatePipe(), CreateFileMapping(), MapViewOfFile()
  16. Protection
    Provides a mechanism for controlling access to the resources provided by a computer
    system.
    Function:
    Manipulate the permission settings of resource such as files and disks.
    Allows user to allow or deny to the access of certain particular resource.
    Ex: For UNIX OS – chmod(), umask(), chown()
    For Windows OS – SetFileSecurity(), InitlializeSecurityDescriptor(),
    SetSecurityDEscriptorGroup()
    19
    Important System Calls in OS
    fork()
    Processes use this system call to create processes that are a copy of themselves. With the help of
    this system Call parent process creates a child process, after fork, both parent and child executes
    the same program but in separate processes. It is primary method of process creation in UNIX like
    OS.
    exec()
    After a fork() system call, one of the two processes typically uses the exec() system call to replace
    the process’s memory space with a new program. The exec() system call loads a binary file into
    memory (destroying the memory image of the program containing the exec() system call) and
    starts its execution. In this manner, the two processes are able to communicate and then go their
    separate ways. The parent can then create more children; or, if it has nothing else to do while the
    child runs, it can issue a wait () system call to move itself off the ready queue until the termination
    of the child.
    wait()
    In some systems, a process needs to wait for another process to complete its execution. This type
    of situation occurs when a parent process creates a child process, and the execution of the parent
    process remains suspended until its child process executes.
    The suspension of the parent process automatically occurs with a wait() system call. When the
    child process ends execution, the control moves back to the parent process.
    exit()
    The exit() system call is used to terminate program execution. Specially in the multi-threaded
    environment, this call defines that the thread execution is complete. The OS reclaims resources
    that were used by the process after the use of exit() system call.
    Parent and Child
    The process invoking fork() is called the parent. The new process created as the result of a fork is
    the child of the parent.
    After a successful fork(), the child process is a copy of the parent. The parent and child processes
    execute the same program but in separate processes.
    Interprocess Communication
    Processes executing concurrently in the operating system may be either independent processes or
    cooperating processes.
    Independent Process: Execution of one process does not affect the execution of the other
    processes and does not share any kind of data with each other.
    Cooperative Process: Execution of one process affect the execution of other processes because
    they share common variable, memory, code or resources parallelly.
    For cooperating processes, we need Interprocess Communication.
    There are several reason for providing an environment that allows process cooperation.
  17. Information sharing: Since several users may be interested in the same piece of information
    (for instance, a shared file), we must provide an environment to allow concurrent access to
    such information

Computation speedup: if we want a particular task to run faster, we must break it into
subtasks, each of which will be executing in parallel with the others. Notice that such a
speedup can be achieved only if the computer has multiple processing cores.

  1. Modularity: We may want to construct the system in a modular fashion, dividing the system
    function into separate processes or threads.
  2. Convenience: Even an individual user may work on many task at the same time. For instance,
    a user may be editing, listening to music, and compiling in parallel.
    Cooperating processes require an interprocess communication (IPC) mechanism that will allow
    them to exchange data and information. There are two fundamental models of interprocess
    communication: shared memory and message passing.
    Shared Memory
    In the shared-memory model, a region of memory that is shared by cooperating processes is
    established. Processes can then exchange information by reading and writing data to the shared
    region. Shared memory can be faster than message passing, since message-passing systems are
    typically implemented using system calls and thus require the more time-consuming task of kernel
    intervention. In shared-memory systems, system calls are required only to establish shared
    memory regions. Once shared memory is established, all accesses are treated as routine memory
    accesses, and no assistance from the kernel is required.
    Message Passing
    In the message-passing model, communication takes place by means of messages exchanged
    between the cooperating processes. Message passing is useful for exchanging smaller amounts of
    data, because no conflicts need be avoided. Message passing is also easier to implement in a
    distributed system than shared memory.

Process Synchronization
Process Synchronization is the task of coordinating the execution of processes in a way that no two processes can have access to the same shared data and resources. It is specially needed in multiprocessing system when multiple processes are running together, and
more than one processes try to gain access to the same shared resource or data at the same time. This can lead to the inconsistency of shared data. So the changes made by one process not necessarily reflected when other processes accessed the same shared data. To avoid this type of inconsistency of data, the process need to be synchronized. Process synchronization problem arises in the case of cooperative process, because resources are
shared in cooperative processes.
FIGURE 8: COMMUNICATIONS MODELS (A) MESSAGE PASSING (B) SHARED MEMORY
21
Race Condition
When more than one processes are executing the same code or accessing the same memory or
any shared variable parallelly, in that condition there is a possibility that the output or the value
of the shared variable is wrong so for that all the processes doing the race to say that my output
is correct this condition known as a race condition. Mainly this condition is a situation that may
occur inside the critical section.
Example: Let P1 is the process which is trying to add 1 in a variable X, (where X = 5), whereas P2 is
a process which is trying to subtract 1 from the same variable X.
Let assume for some reason before printing the value of X from 5 to 6 P1 gets preempt and CPU is
now allotted to process P2. In this case now P2 will starts its execution and subtract 1 from the X =
5 and makes it 4 but again before printing it also gets preempt. Now again due to context
switching CPU gets allotted to P1 and it continues its execution from where preemption occurred
and it print X = 6. After the completion of process P1 again CPU is now allotted to P2 and it also
stats it left execution and print X = 4
But, due to race condition the value of X get printed wrong, actually the final value that should be
printed is 5.
So, to overcome from this situation we need to synchronize the processes.
Critical Section
Each process has a segment of code in which the process may be changing common variables,
updating a table, writing a file, and so on, or a section that consist of shared data resources that
can be accessed by other processes, is called critical section. The important feature of the system
is that, when one process is executing in critical section, no other process is allowed to execute in
it.

Entry Section: It is part of process which decides the entry of a particular process.
Exit Section: It allows the other process that are waiting in the Entry Section, to enter into Critical
Section. It also checks that a process that finished its execution should be removed through this
section.
Remainder Section: All the other parts of the code, which is not in Critical, Entry, and Exit Section,
are known as the Remainder Section.
There are some conditions that must be satisfy by any synchronization method (or critical-section
problem) to achieve process synchronization.
FIGURE 9: GENERAL STRUCTURE OF A TYPICAL PROCESS
22

  1. Mutual exclusion: If a process is executing in its section, then no other process is allowed to
    execute in the critical section i.e. out of a group of cooperating processes, only one process
    can be in its critical section at a given point of time.
  2. Progress: If no process is executing in its critical section and some processes wish to enter
    their critical section, then only those processes that are not executing in their remainder
    section can participate in deciding which will enter its critical section next, and this selection
    cannot be postponed indefinitely.
    No process running outside the critical section should lock the other process for entering in
    critical section.
  3. Bounded waiting: There exists a bound, or limit, on the number of times that other
    processes are allowed to enter critical section after a process has a made a request to enter
    its critical section and before that request is granted.
  4. No assumption related to no of CPU and Hardware speed
    Deadlock
    In a multiprogramming environment, several processes may compete for a finite number of
    resources. A process requests resources; if the resources are not available at that time, the process
    enters a waiting state. Sometimes, a waiting process is never again able to change state, because
    the resources it has requested are held by other waiting processes. This situation is called a
    deadlock.
    Necessary Conditions for Deadlock
    A deadlock situation can arise if the following four conditions hold simultaneously in a system:
  5. Mutual exclusion: At least one resource must be held in a non-sharable mode; that is, only
    one process at a time can use the resource. If another process requests that resource, the
    requesting process must be delayed until the resource has been released.
  6. Hold and wait: A process must be holding at least one resource and waiting to acquire
    additional resource that are currently being held by other processes.
  7. No preemption: Resource cannot be preempted; that is, a resource can be released only
    voluntarily by the process holding it, after that process has completed its task.
  8. Circular wait: A set {P0, P1, …, Pn} of waiting processes must exist such that P0 is waiting for a
    resource held by P1, P1 is waiting for a resource held by P2, …, Pn−1 is waiting for a resource
    held by Pn, and Pn is waiting for a resource held by P0.
    Resource Allocation Graph (RAG)
     In order to describe deadlocks in a more precise way directed graphs are used that are called
    system resource allocation graph.
     This graph acts as the pictorial representation of the state of the system.
     The resource allocation graph mainly consists a set of vertices V and a set of edges E.
     This graph contains all the information related to the processes that are holding some
    resources and also contains the information of the process that are waiting for some more
    resources in the system.

Also this graph contains all the information that is related to all the instance of the resource
which means the information about available resource that recourse which are being used by
the process.
 In the graph, circle is used to represent the process, and the rectangle is used to represent
the resource.
Components of Resource Allocation Graph
There are two components of Resource Allocation Graph

  1. Vertices
  2. Edges
  3. Vertices
    There are two kinds of vertices used in the resource allocation graph
    a. Process Vertices
    b. Resource Vertices
    a. Process Vertices
    These vertices are used in order to represent process vertices. The circle is used in
    order to draw the process vertices and the name of the process is mentioned inside the circle.
    b. Resource Vertices
    These vertices are used in order to represent resource vertices. The rectangle is used in
    order to draw the resource vertices and we use dots inside the rectangle to mention
    the number of instances of that resource.
    In the system, there may exist a number of instances and according to them, there are
    two types of resource vertices and these are single instances and multiple instance.
    Single Instance
    In a single instance resource type, there is single dot inside the rectangle. The dot
    mainly indicates that there is one instance of the resource. Ex; printer
    Multiple Instance
    In multiple instance resources types, there are multiple dots inside the rectangle,
    and these multiple dots indicates that there are multiple instances of the
    resources. Ex; resistors
  4. Edges
    In the resource allocation graph, edge are further categorized into two types
    a. Assignment Edge
    b. Request Edge
    a. Assignment Edge
    Assignment edge are mainly used to represent the allocation of resource to the
    process. We can draw assignment edge with the help of an arrow in which the
    arrowhead points the process, and tail points to the resource which is allocated to that
    process.
    b. Request Edge
    Request edge is used to signify the waiting state of the process. Likewise, in assignment
    edge, we can also draw the request edge with the help of an arrow but here arrowhead
    points to the resource for which process is waiting and tails points to the process.

If there is a cycle in single instance resource allocation graph, then there must be a deadlock. Here, in the above RAG (Fig 11) resource R2 is assigned/allocated to the process P1 but P1 is
requesting for the resource R1. Also resource R1 is assigned to process P2 but P2 is requesting for the resource R2. So the above RAG forms a cycle and hence P1 & P2 is in deadlock.

Here in the above example (Fig 12), processes P1 and P2 acquiring resources R1 and R2 while process P3 is waiting to acquire both resources. In this example, there is no deadlock because
there is no circular dependency.
So cycle in single-instance resource type is the sufficient condition for deadlock.

Here in the above multiple instance RAG (Fig 13) there is two cycle, in which resource R2 is
assigned to process P1 & P2 and P1 is waiting for R1, R1 is assigned to process P2 and P2 is waiting for resource R3 and resource R3 is assigned to process P3 but P3 is waiting for R2. Hence all the
processes (P1, P2 and P3) are in deadlock.
P1  R1  P2  R3  P3  R2  P1
P2  R3  P3  R2  P2

Now consider the resource allocation graph in Fig 14. In this example, we also have cycle:
P1  R1  P3  R2  P1
However, there is no deadlock. Process P4 may release its instance of resource type R2. That resource can then be allocated to P3, breaking the cycle.
In summary, if a resource allocation graph does not have a cycle, then the system is not in a
dead lock state. If there is a cycle, then the system may or may not be in deadlocked state,
especially in the case of multiple instance resource. Method for Handling Deadlock
We can deal with the deadlock problem in one of three ways:
We can use a protocol to prevent or avoid deadlocks, ensuring that the system will never enter a deadlock state. We can allow the system to enter a deadlock state, detect it, and recover. We can ignore the problem altogether and pretend that deadlock never occur in the system. To ensure that deadlocks never occur, the system can use either a deadlock prevention or a
deadlock-avoidance scheme.
Deadlock prevention provides a set of methods to ensure that at least one of the necessary
conditions cannot hold. These methods prevent deadlocks by constraining how requests for
resources can be made.
Deadlock avoidance requires that the operating system be given additional information in
advance concerning which resources a process will request and use during its lifetime. With this additional knowledge, the operating system can decide for each request whether or not the
process should wait. To decide whether the current request can be satisfied or must be delayed,
the system must consider the resources currently available, the resources currently allocated to
each process, and the future requests and releases of each process. Memory Management
Memory is Central to the operation of a modern computer system. Memory consist of a large array of words or bytes. Each with its own address. The CPU fetches instructions from memory, these instructions may cause additional loading from and storing to specific memory addresses. A typical instructions-execution cycle, for example, first fetches an instruction from memory. The
instruction is then decoded and make cause operands to be fetched from memory. After the
instruction has been executed on the operands, results may be stored back in memory. The
memory unit sees only a stream of memory addresses; it does not know how they are generated
or what they are for. There are various techniques for managing memory, this includes basic
hardware issue’s, the binding of symbolic memory addresses to actual physical addresses, and
distinction between logical and physical addresses. Main memory and registers built into the processor are the only storage that CPU can access directly. Therefore, any instructions in
execution and any data being used by the instructions, must be in the direct access storage device. If the data are not in the memory, they must be moved there before the CPU can operate on them

Need of Memory Management

  1. This technique helps in placing the programs in memory in such a way so that memory is
    utilized at its fullest extent.
  2. This technique helps to protect different processes from each other so that they do not
    interfere with each other’s operations.
  3. It helps to allocate space to different application routines.
  4. This technique allows you to check how much memory needs to be allocated to processes
    that decide which processor should get memory at what time.
  5. It keeps the track of each memory location whether it is free or allocated.
  6. This technique keeps the track of inventory whenever memory gets freed or unallocated and
    it will update the status accordingly.
    Address Binding
    To be executed, the program must be brought into memory and placed within a process. The
    process may be moved between disk and memory during its execution. The processes on the disk
    that are waiting to be brought into memory for execution form the input queue. The normal
    procedure is to select one of the processes in the input queue and to load that process into
    memory. As the process is executed, it accesses instructions and data from memory. Addresses
    may be represented in different ways during these steps. Addresses in the source program are
    generally symbolic. A compiler typically binds these symbolic addresses to relocatable addresses.
    The linkage editor or loader in turn binds the relocatable addresses to absolute addresses. Each
    binding is a mapping from one address space to another.
    The binding of instructions and data to memory addresses can be done at any step along the way:
    Compile time: If you know at compile time where the process will reside in memory, then absolute
    code can be generated.
    Load time: If it is not known at compile time where the process will reside in memory, then the
    compiler must generate relocatable code. In this case, final binding is delayed until load time.
    Execution time: If the process can be moved during its execution from one memory segment to
    another, then binding must be delayed until run time.
    Logical Versus Physical Address Spaces
    An address generated by the CPU is commonly referred to as a logical address, whereas an address
    seen by the memory unit is commonly referred to as a physical address. The compile-time and
    load-time address-binding methods generate identical logical and physical addresses. However,
    the execution-time address binding scheme results in differing logical and physical addresses. The
    set of all logical addresses generated by a program is a logical address space. The set of all physical
    addresses corresponding to these logical addresses is a physical address space. Thus, in the
    execution-time address-binding scheme, the logical and physical address spaces differ. The runtime mapping from virtual to physical addresses is done by a hardware device called the memorymanagement unit (MMU). The user program never sees the real physical addresses. The program
    can create a pointer to location store it in memory, manipulate it, and compare it with other
    addresses. The user program deals with logical addresses. The memory-mapping hardware
    converts logical addresses into physical addresses.
    Dynamic Loading
    The entire program and all data of a process must be in physical memory for the process to
    execute. The size of a process has thus been limited to the size of physical memory. In order to
    28
    obtain better memory-space utilization, we can use dynamic loading. With dynamic loading, a
    routine is not loaded until it is called. All routines are kept on disk in a relocatable load format. The
    main program is loaded into memory and is executed. When a routine needs to call another
    routine, the calling routine first checks to see whether the other routine has been loaded. If it has
    not, the relocatable linking loader is called to load the desired routine into memory and to update
    the program’s address tables to reflect this change. Then control is passed to the newly loaded
    routine. The advantage of dynamic loading is that unused routine is never loaded. Dynamic loading
    does not require special support from the operating system. It is the responsibility of the users to
    design their programs to take advantage of such a method.
    Dynamic Linking and Shared Libraries
    Dynamically linked libraries are system libraries that are linked to user programs when the
    programs are run. With dynamic linking, a stub is included in the image for each library routine
    reference. The stub is a small piece of code that indicates how to locate the appropriate memoryresident library routine or how to load the library if the routine is not already present. When the
    stub is executed, it checks to see whether the needed routine is already in memory. If it is not, the
    program loads the routine into memory. Either way, the stub replaces itself with the address of
    the routine and executes the routine.
    Swapping
    A process must be in memory to be executed. A process can be swapped temporarily out of
    memory to a backing store and then brought back into memory for continued execution. If a
    higher-priority process arrives and wants service, the memory manager can swap out the lowerpriority process and then load and execute the higher-priority process. When the higher-priority
    process finishes, the lower-priority process can be swapped back in and continued. This variant of
    swapping is sometimes called roll out, roll in.
    Contiguous Memory Allocation
    The memory is usually divided into two partitions: one for the resident operating system and one
    for the user processes. We usually want several user processes to reside in memory at the same
    time. In contiguous memory allocation, each process is contained in a single contiguous section of
    memory.
    One of the simplest methods for allocating memory is to divide memory into several fixed-sized
    partitions. Each partition may contain exactly one process. The degree of multiprogramming is
    bound by the number of partitions. In this multiple partition method, when a partition is free, a
    process is selected from the input queue and is loaded into the free partition. When the process
    terminates, the partition becomes available for another process. In the variable-partition scheme,
    the operating system keeps a table indicating which parts of memory are available and which are
    occupied. Initially, all memory is available for user processes, and is considered as one large block
    of available memory, a hole. When a process arrives and needs memory, we search for a hole large
    enough for this process. If we find one, we allocate only as much as memory is needed, keeping
    the rest available to satisfy future requests.
    As processes enter the system, they are put into an input queue. The operating system takes into
    account the memory requirements of each process and the amount of available memory space in
    determining which processes are allocated memory. When a process is allocated space, it is loaded
    into memory and it can then complete for the CPU. When a process terminates, it releases its
    memory, which the operating system may then fill with another process from the input queue.
    At any given time, we have a list of available block and input queue. The operating system can
    order the input queue according to a scheduling algorithm. Memory is allocated to process until,
    29
    finally, the memory requirement for the next process cannot satisfied; no available block of
    memory (or hole) is large enough to hold that process. The operating system can then wait until a
    large enough block is available, or it can skip down the input queue to see whether the smaller
    memory requirements of some other process can be met.
    In general, set of holes, of various size, is scattered throughout memory at any given time. When a
    process arrives and needs memory, the system searches the set for a hole that is large enough for
    this process. If the hole is too large, it is split into two parts. One part is allocated to the arriving
    process; the other is returned to the set of holes. When a process terminates, it releases its block
    of memory, which is then placed back in the set of holes. If the new hole is adjacent to other holes,
    these adjacent holes are merged to form one larger hole.
    The first-fit, best-fit, and worst-fit strategies are the ones most commonly used to select a free
    hole from the set of available holes.
    First fit: Allocate the first hole that is big enough. Searching can start either at the beginning of the
    set of holes or at the location where the previous first-fit search ended. We can stop searching as
    soon as we find a free hole that is large enough.
    Best fit: Allocate the smallest hole that is big enough. We must search the entire list, unless the list
    is ordered by size. This strategy produces the smallest leftover hole.
    Worst fit: Allocate the largest hole. Again, we must search the entire list, unless it is sorted by size.
    This strategy produces the largest leftover hole, which may be more useful than the smaller
    leftover hole from a best-fi approach.
    Fragmentation
    The first-fit and best-fit strategies for memory allocation suffer from external fragmentation. As
    processes are loaded and removed from memory, the free memory space is broken into little
    pieces. External fragmentation exists when there is enough total memory space to satisfy a
    request but the available spaces are not contiguous: storage is fragmented into a large number of
    small holes. This fragmentation problem can be severe.
    Solution to the problem of external fragmentation is compaction. The goal is to shuffle the
    memory contents so as to place all free memory together in one large block. The simplest
    compaction algorithm is to move all processes toward one end of memory; all holes move in the
    other direction, producing one large hole of available memory. This scheme can be expensive.
    Compaction is not always possible, however. If relocation is static and is done at assembly or load
    time, compaction cannot be done. It is possible only if relocation is dynamic and is done at
    execution time.
    Paging
    Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage in
    to the main memory in the form of pages. In the paging method the main memory divided into
    small fixed size block is called frames. The size of a frame should be kept same as that of all page
    to have maximum utilization of the main memory and to avoid external fragmentation paging is
    used for faster access to data and it is a logical concept.
    Every address generated by the CPU is divided into two parts a page number (p) and a page offset
    (d). The page number is used as an index into a page table. The page table contains the base
    address of each page in physical memory. This base address is combined with the page offset to
    define the physical memory address that is sent to the memory unit.
    30
    Segmentation
    Segmentation is a memory-management scheme that supports this programmer view of memory.
    A logical address space is a collection of segments. Each segment has a name and a length. The
    addresses specify both the segment name and the offset within the segment. The programmer
    therefore specified each address by two quantities: a segment name and an offset. The
    programmer can now refer to objects in the program by a two-dimensional address, the actual
    physical memory is still, of course, a one dimensional sequence of bytes. Thus, we must define an
    implementation to map two-dimensional user-defined addresses into one-dimensional physical
    addresses. This mapping is effected by a segment table. Each entry in the segment table has a
    segment base and a segment limit. The segment base contains the starting physical address where
    the segment resides in memory, and the segment limit specifies the length of the segment. The
    segment table has a separate entry for each segment
    Virtual Memory
    Virtual memory is a technique that allows the execution of processes that are not completely in
    memory. One major advantage of this scheme is that programs can be larger than physical
    memory. Further, virtual memory abstracts main memory into an extremely large, uniform array
    of storage, separating logical memory as viewed by the user from physical memory. This technique
    frees programmers from the concerns of memory-storage limitations. Virtual memory also allows
    processes to share files easily and to implement shared memory. In addition, it provides an
    efficient mechanism for process creation.
    The ability to execute a program that is only partially in memory would confer many benefits:
  7. A program would no longer be constrained by the amount of physical memory that is
    available. Users would be able to write programs for an extremely large virtual address
    space, simplifying the programming task.
  8. Because each user program could take less physical memory, more programs could be run at
    the same time, with a corresponding increase in utilization and throughput but with no
    increase in response time or CPU turnaround time.
  9. Less I/O would be needed to load or swap user programs into memory, so I/O each user
    program would run faster.
    Virtual memory involves the separation of logical memory as perceived by users from physical
    memory. This separation allows an extremely large virtual memory to be provided for
    programmers when only a smaller physical memory is available. Virtual memory makes the task of
    programming much easier, because the programmer no longer needs to worry about the amount
    of physical memory available.
    The virtual address space of a process refers to the logical (or virtual) view of how a process is
    stored in memory.
    In addition to separating logical memory from physical memory, virtual memory allows files and
    memory to be shared by two or more processes through page sharing. This leads to the following
    benefits:
  10. System libraries can be shared by several processes through mapping of the shared object
    into a virtual address space. Although each process considers the libraries to be part of its
    virtual address space, the actual pages where the libraries reside in physical memory are
    shared by all the processes. Typically, a library is mapped read-only into the space of each
    process that is linked with it.
    31
  11. Similarly, processes can share memory. Virtual memory allows one process to create a region
    of memory that it can share with another process. Processes sharing this region consider it
    part of their virtual address space, yet the actual physical pages of memory are shared.
  12. Pages can be shared during process creation with the fork () system call, thus speeding up
    process creation.

Leave a Comment

Your email address will not be published.