Basic Operating System Concepts
Basic Operating System Concepts
Basic Operating System Concepts
Concepts
A Review
Main Goals of OS
1. Resource Management: Disk, CPU cycles,
etc. must be managed efficiently to
maximize overall system performance
2. Resource Abstraction: Software interface
to simplify use of hardware resources
3. Virtualization: Supports resource sharing –
gives each process the appearance of an
unshared resource
System Call
• An entry point to OS code
• Allows users to request OS services
• API’s/library functions usually provide an
interface to system calls
– e.g, language-level I/O functions map user
parameters into system-call format
• Thus, the run-time support system of a prog.
language acts as an interface between
programmer and OS interface
Some UNIX System Calls
• System calls for low level • System Calls for process
file I/O control
– creat(name, permissions) – fork()
– open(name, mode) – wait()
– close(fd) – execl(), execlp(), execv(),
– unlink(fd) execvp()
– read(fd, buffer, n_to_read) – exit()
– write(fd, buffer, n_to_write) – signal(sig, handler)
– lseek(fd, offest, whence) – kill(sig, pid)
• System Calls for IPC
– pipe(fildes)
– dup(fd)
Execution Modes
(Dual Mode Execution)
• User mode vs. kernel (or supervisor) mode
• Protection mechanism: critical operations
(e.g. direct device access, disabling
interrupts) can only be performed when the
OS is in kernel mode
• Mode bit
• Privileged instructions
Mode Switching
• System calls allow boundary to be crossed
– System call initiates mode switch from user to
kernel mode
– OS executes kernel code, mode switch occurs
again when control returns to user process
– Special instruction – “software interrupt” – to
call a kernel function – transfers control to a
location in the interrupt vector
Processing a System Call*
• Switching between kernel and user mode is time
consuming
• Kernel must
– Save registers so process can resume execution
• Other overhead is involved; e.g. cache misses, & prefetch
– Verify system call name and parameters
– Call the kernel function to perform the service
– On completion, restore registers and return to caller
Review Topics
• Processes &Threads
• Scheduling
• Synchronization
• Memory Management
• File and I/O Management
Review of Processes
• Processes
– process image
– states and state transitions
– process switch (context switch)
• Threads
• Concurrency
Process Definition
• A process is an instance of a program in
execution.
• It encompasses the static concept of
program and the dynamic aspect of
execution.
• As the process runs, its context (state)
changes – register contents, memory
contents, etc., are modified by execution
Processes: Process Image
• The process image represents the current status of
the process
• It consists of (among other things)
– Executable code
– Static data area
– Stack & heap area
– Process Control Block (PCB): data structure used to
represent execution context, or state
– Other information needed to manage process
Process Execution States
• For convenience, we describe a process as
being in one of several basic states.
• Most basic:
– Running
– Ready
– Blocked (or sleeping)
Process State Transition Diagram
preempt
ready running
dispatch
blocked
Other States
• New
• Exit
• Suspended (Swapped)
– Suspended blocked
– Suspended ready
Context Switch
(sometimes called process switch)
Sequential
I: A1, A2, A3, A4, A5, …, Am, B1, B2, B3, B4, B5, B6, …, Bn
Interleaved
II: B1, B2, B3, B4, B5, A1, A2, A3, B6, …, Bn, A4, A5, …
III: A1, A2, B1, B2, B3, A3, A4, B4, B5, …, Bn, A5, A6, …, Am
Process Synchronization – 2 Types