Os Notes Mod 2
Os Notes Mod 2
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
INTERRUPTS
SYSTEM CALL
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
CONTEXT SWITCHING
THREADS
USER THREADS
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;