You are on page 1of 30


operating system (OS) is the system

software responsible for the direct
control and management of hardware
and basic system operations.
Additionally, it provides a foundation
upon which to run application software
Few OSs
1973 Unix – the first kernel written in a portable
programming language
1975 VAX/VMS
1981 MS-DOS.
1983 AmigaOS
1984 Macintosh
1987 OS/2
1993 FreeBSD
Unix variations

Digital UNIX (or DUNIX) • OpenBSD
GNU Hurd
• Pyramid
• Rhapsody
Mac OS X • Solaris
Mac OS X Server • SunOS
Kernel driver

• Kernel driver can be:

• System driver – implement a system feature
like file system or TCP/IP stack.
• Hardware driver – implement a specific
hardware interface to the OS kernel.
Hardware drivers

• Provide general interface for the OS to access

different brands with similar functionality.
• For example all NICs driver have the same interface
while each driver “speak” differently to its NIC
• Hardware driver are layered!
• The NIC drivers call the PCI drivers and so on.
File System

• Used mainly on Hard disks.

• Provide directory hierarchy
• And files with names and attributes.
• Can provide security.
• Modern file system provide journal for
power fail recovery
• Example: FAT, NTFS, ext2, ext3, raiserfs.
TCP/IP stack

• Network stack layer 3.

• Most OS today comes with it’s own stack.
• However it is not a most!
• In Linux the TCP/IP stack is a kernel driver.
Memory management

• Allocating memory in the form pages.

• Separate kernel pages from user space pages
• Activate the MMU (next slide)
• Handle mapping of virtual addressing to
physical memory.
• Kernel uses physical memory addressing.
Memory management unit

• Hardware component that provides:

• Memory Protection
• Access per mode.
• Access can be read/write, read only and no
• There is one access for data and one for
instruction fetch (running code)
• Also enable the use of swap!
Memory management unit …

• Virtual Addressing mapping:

• Map real memory to virtual addressing.
• Enable the OS to manipulate application
memory addressing.
• Enable fork!
Swap file system

• A Kernel driver that control the virtual

memory that is located on the hard disk. This
memory belongs to application that are
sleeping. When this application arise the
kernel driver will fetch their memory from
the hard disk back to physical memory.
• Work tightly with the MM component.

• Processors are object of the OS that have: stack,

heap, code and data, all mapped by the OS. Each
Processors have it’s own CPU registers which
includes program counter and stack pointer.
• The process memory is unique and can access only
by the OS when needed.
• Each Process has its user ID and all other security

• Threads are OS objects that exist inside a

process. Each Thread has it’s own registers
and stack. But share the same memory space!
• The process itself is then called the main

• Exist in system that do not use memory

mapping, so all process are like threads
running in one process, which is the OS
• In this case we call them tasks.

• The Scheduler is a machine inside of the kernel that

share the CPU among all process and threads in the
system include the kernel itself!
• The Scheduler share the CPU by priority and by
• A good Scheduler can improve system
performance, and should fit the OS main purpose of
• Can share two or more CPUs among processes.

• The OS has a code loader.

• The loader can load kernel driver into the kernel
and application (process) into the user space.
• The Linux load recognize elf a.out and coff
• The loader perform dynamic link to resolve all of
the new module unresolved links.
• In case of application to load all the libraries
required by the new application.
Blocking and non-blocking

• Blocking operation is an operation that

blocks the thread (or process) until the
condition is true. In this case the Scheduler
will move to other threads.
• Blocking operation can have time-out.
• non-blocking operation returns immediately
without waiting.

• Usually Pure blocking call (could be with

timeout) for an event to happen.
• An event could be for example key pressed.
• In this case the thread will wait until use
press a key. (Just like this slide)

• When two threats or tasks use the same resource,

they must use a sort of a lock mechanism. This is
the Semaphore.
• There are three basic kinds:
• Binary semaphore – lock or not.
• Count semaphore – can be obtain several times
before it is locked!
• Mutex – thread depended semaphore. Can be obtain
endlessly by the same thread that lock it.
• Obtain Semaphore can be blocking call or not.
Inter process communication

• Message queues.
• Shared Memory
• Sockets (network!)
Message queue

• Sending messages between processes,

threads or tasks.
• In case of threads we can pass only the
pointer to a memory block. That is all needed
since they all live in the same memory space!
• In case of process we should pass all the
message since there is memory sharing
between two processes.
Shared Memory

• A block of memory that can be shared by

several processes.
• This enable different processes which by
default live each in it’s own memory space to
share a memory block together.
• In this case a semaphore is needed to avoid
accident write by two processes to the same
memory block on the same time!.
CPU modes

• Most CPU provide at least two mode of operation

(Usually there are more!)
• System mode – is provide for the OS for it’s normal
operation. This mode has full privilege and full
memory access.
• User mode – Application area mode. In this mode,
processes can access only their own memory, using
the virtual memory supplied by the OS.
Kernel versa OS

• Kernel contains only the area that works in system

mode (or other privilege modes as interrupt or
exception modes)
• The OS contains the Kernel and other component
that runs in user mode but are related to the OS
itself like the X-server, the init process.
• Processors and threads can run inside the kernel,
outside as part of applications or part of the system.
System calls (syscalls)

• The bridge between kernel and outside the

• Syscalls are the fastest way to invoke the
underling system
• Most CPUs this day have system call for this
GlibC and the standard library

• GNU standard library for C based

• Implement all of the C standard functions.
• Use the system calls to call the underlying
OS as needed!
POSIX standard

• IEEE standard
• Stand for Portable Operating System
• A standard interface to the underlying OS.
• Linux today have libraries to support POSIX.
Interrupt, and interrupt handler

• Interrupt is issued by hardware on an event.

• For example, the timer interrupt interrupt every few
CPU cycles or every few micro seconds.
• For each interrupt there is interrupt handler which is
a routine part of the OS that handles this event
process it as needed.
• For example a NIC interrupt will be a network
packet that should be forward to the TCP/IP stack.
Exceptions and exceptions
• Exception are issued by the CPU when a wrong
instruction is issued.
• Exception could be for example, divide by zero and
access inaccessible memory.
• Each exception has it’s own handler, the exception
handler in case of application will create a core
dump and clear the application from the memory.
(or call the debugger directly in case of windows)
Classification of system

• multi-user : Allows two or more users to run

programs at the same time.
• multiprocessing : Supports running a program on
more than one CPU.
• multitasking : Allows more than one program to run
• Embedded: special-purpose computer system,
which is completely encapsulated by the device it
• real time: Responds to input instantly.