0% found this document useful (0 votes)
47 views9 pages

Os Notes Mod 2

The document discusses the difference between kernel mode and user mode in an operating system. It covers topics like system calls, interrupts, process scheduling, and threads. The key differences are: 1. Programs in kernel mode have direct access to system resources while programs in user mode must use system calls. 2. If an interrupt occurs, the whole OS fails in kernel mode while only the single process fails in user mode. 3. All processes share a single virtual address space in kernel mode and get separate virtual address spaces in user mode. 4. To switch from user to kernel mode, a system call must be made which triggers a software interrupt that transfers control to the interrupt handler in the
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views9 pages

Os Notes Mod 2

The document discusses the difference between kernel mode and user mode in an operating system. It covers topics like system calls, interrupts, process scheduling, and threads. The key differences are: 1. Programs in kernel mode have direct access to system resources while programs in user mode must use system calls. 2. If an interrupt occurs, the whole OS fails in kernel mode while only the single process fails in user mode. 3. All processes share a single virtual address space in kernel mode and get separate virtual address spaces in user mode. 4. To switch from user to kernel mode, a system call must be made which triggers a software interrupt that transfers control to the interrupt handler in the
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

DIFFERENCE BETWEEN KERNEL AND USER MODE

KERNEL USER
Program has direct and unrestricted access no direct access to system resources, must
to system resources use a system call
Whole os fails if interrupt occurs A single process fails if interrupt occurs
All processes share a single virtual address All processes get separate virtual address
space space
Applications have more privilege Less privilege
Can access both user and kernel programs Cannot access kernel programs directly
System crash makes it difficult to recover Can be easily recovered by resuming the
session
Known as system mode Known as restricted mode

SWITCHING FROM USER TO KERNEL MODE

 To switch from user to kernel mode we must use a system call


 When we call a system call API, a Soft Ware Interrupt (SWI) / exception occurs
 This shift control from user application to a location in the interrupt vector table
(IVT) given by the OS
 IVT is a data structure that associates interrupt handlers to interrupt requests
 Each entry in the IVT Is an address of an interrupt handler

INTERRUPTS

 It is a part of OS and runs in kernel mode


 They are signals sent to CPU that stop the current execution and transfers control to
the appropriate part of the OS
 Two types:
o Hardware interrupt: caused by hardware devices like I/O devices
o Software interrupt: caused by software, usually user programs in user mode

SYSTEM CALL

 It is the programming interface between the services provided by the OS


 Written in high level languages (C OR C++)
 Accessed by user programs by high level Application Program Interface (API)
 Types of API: WIN32 API for WINDOWS, POSIX API for POSIX based systems and JAVA
API for Java Virtual Machine (JVM)
How a system call works

TYPES OF SYSTEM CALLS

 Process control
o Create & terminate process
o Get & set process attributed
o Allocate & free memory
o Wait for time
o Wait event & signal event
o Load & execute
o End & abort
 File management
o Create & delete file
o Open & close file
o Get & set file attributes
o Read, Write & reallocate
 Device management
o Request & release device
o Get & set device attributes
o Read, Write & reallocate
o Logically attach & detach device
 Information maintenance
o Get & set Time or Date
o Get & set System date
o Get & set Process, File & Device attributes
 Communication
o Create & delete communication connections
o Send & receive messages
o Transfer status information
o Attach or detach remote devices

PROCESS

 It is a program in execution
 Program is passive whereas process is active
 PARTS OF A PROCESS:
o Text section: is the program code
o Program counter holds address of instruction
o Stack: contains temporary data (function calls)
o Data section: contains global variables
o Heap : contains dynamically allocated memory during run time

PROCESS STATES

 5 states
o NEW: process created
o RUNNING: process executed
o WAITING: process waiting for an event
o READY: process waiting to be assigned
o TERMINATED: process finishes executing

PROCESS SCHEDULING

 Maximizes CPU utilization


 Selects among available processes for execution
 Scheduling queues, 3 types
o Job queue: holds all the processes
o Ready queue: holds processes ready for execution
o Devic queue: holds processes waiting for an input or output device
 Two types of process scheduling
 Long term (job scheduler)
o Selects which process to be brought into the ready queue
o Invoked very infrequently
 Short term (CPU scheduler)
o Selects which process to be executed and allocate CPU
o Invoker very frequently

CONTEXT SWITCHING

 CPU switches from one process to another


 This is done by saving the current state of old process and reloading the saved
state of the new process

THREADS

 It is the basic unit of CPU utilization


 Consists of program counter, Stack, Set of registers & Thread ID
 Traditional program usually have a single thread of control

SINGLE AND MULTI THREADED PROCESSES


MULTI THREADED SERVER ARCHITECTURE

USER THREADS

 Threads managed by user thread libraries


 EX:
o POSIX PTHREADS
o WINDOWS THREADS
o JAVA THREADS
KERNEL THREADS

 Threads supported by kerner


 EX: windows, linux, solaris

MULTI THREADDING MODELS

 MANY TO ONE
o Many user threads mapped to a single kernel thread
o Cannot run in parallel in multicore system
o 1 thread blocking blocks all threads

 ONE TO ONE
o Each user thread mapped to a Single kernel thread
o More concurrency than many to one

 MANY TO MANY
o Many user threads mapped to many kernel threads
o OS can create sufficient number of kernel threads
 TWO LEVEL MODEL (many to many and one to one at the same time)
o Allows a user thread to be bound to a kernel thread
PARENT CHILD PROGRAM

#include <stdio.h>

#include<unistd.h>

#include<sys/types.h>

int main() {

int n ;

printf("enter number");

scanf("%d",&n);

int a;

printf("enter no of nos");

scanf("%d",&a);

int i;

int d = 0;

for(i=0;i<a;i++){

int c;

scanf("%d",&c);

d+=c;

if(fork()==0){
printf("the sum of the given numbers is %d",d);

else{

printf("parent");

int t;

int s= 1;

for(t=1;t<=n;t++){

s*=t;

printf("factorial is %d",s);

return 0;

You might also like