DevOps Linux Lecture-1
DevOps Linux Lecture-1
www.corvit.com
Topics
• What is an OS?
• Computer System Organization
• Multiprogramming vs Multitasking
• User Mode & Kernel Mode
• System Call, Interrupt, Trap & Signal
• Processes
• Threads
• Scheduling Algorithms
• Linux History
• Pros & Cons
• Distributions
• Virtualization
www.corvit.com
What is an OS?
• An OS is a program running at all times on the computer (usually
called the kernel), that controls the execution of application
programs and acts as an interface between the user of a
computer and the computer hardware
• Provides an orderly and controlled allocation of the processor(s),
memory(ies) and I/O devices among the various programs
competing for them.
• Sits between programs & hardware
• Sits between different programs
• Sits between different users
• Primary goal of OS is convenience of user and secondary goal is
efficient operation of the computer system.
www.corvit.com
Operating System - An Abstraction
www.corvit.com
Operating System - An Abstraction
www.corvit.com
Operating System - An Abstraction
www.corvit.com
Operating System - An Abstraction
www.corvit.com
Operating System - An Abstraction
www.corvit.com
Computer System Organization
www.corvit.com
Multiprogramming vs Multitasking
Multiprogramming Multitasking
www.corvit.com
Protection
In Multitasking there are multiple processes using various
resources of the computer. Sounds great, but like no free
lunch, it has disadvantage as well, i.e. the issue of
protection
• Keep user programs from crashing the OS
• Keep user programs from crashing each other
• Keep parts of OS from crashing other parts
Protection is implemented by keeping two modes
www.corvit.com
Dual Mode Operation
To protect the OS and all other programs and their data from any
malfunctioning program, protection is needed for any shared
resource. It is done by keeping two modes:
User Mode. Execution done on behalf of a user program
Monitor/Kernel/System/Supervisor Mode. Execution done on behalf
of OS
Mode bit added to computer h/w to indicate the current mode:
Kernel(0), User (1)
When an interrupt or fault occurs hardware switches to monitor
mode. Privileged instructions can only be executed in monitor mode.
www.corvit.com
Transition from User to Kernel Mode
• A user process must not be given an open access to kernel code
• Any user/application request that involves access to any system
resource must be handled by the kernel code
• The mechanism used by an application program to request a
service from Operating System is via a system call
• A System call is usually a request to the OS kernel to do a h/w,
system specific or privileged operation.
www.corvit.com
Types of Entry Points to Kernel
• When a program makes a System Call.
• Interrupt: An event generated by an I/O device to get the
attention of CPU and control goes to the OS. When an I/O device
has generated an Interrupt; e.g. a disk controller has generated
an interrupt to CPU that my reading is complete the data is now
sitting in my buffer, You can go and get it.
• Trap: An event generated by CPU and control goes to the OS.
When a trap occurs; e.g. If a program has made a division by
zero, a trap will be generated which will execute a different
piece of code in kernel (.
• Signal: A notification given to a process by the OS because the
process did something, the user did something, one process
wants to tell another process something. When a signal comes
to a process some piece of kernel code will be executed
www.corvit.com
System Call
A system call is the controlled entry point
into the kernel code, allowing a process to
request the kernel to perform a privileged
operation. Before going into the details of
how a system call works, following points
need to be understood:
• A system call changes the processor
state from user mode to kernel mode, so
that the CPU can access protected kernel
memory
• The set of system calls is fixed. Each
system call is identified by a unique
number
• Each system call may have a set of
arguments that specify information to be
transferred from user space to kernel
space and vice versa
• All OS’s offer their own System Calls
www.corvit.com
Users, Programs and Processes
• Users have accounts on the system. Users write programs, then
execute programs. Different users may execute same program.
One user may execute many instances of the same program
• A Program by itself is not a Process: Program is a passive entity
like the contents of a file stored on a disk. Process is an active
entity, in which the Program Counter specifies the next
instruction to be executed
• A Process is
A program in execution
An instance of a program running on a computer
An entity that can be assigned to and executed on a processor
• The UNIX system creates a process every time you run an
external command, and the process is removed from the system
when the command finishes its execution
www.corvit.com
CPU Bound and I/O Bound Processes
• I/O-bound process – spends more time doing I/O than
computations; Many short CPU bursts
• Examples: Word processing, text editors. Billing system of
WAPDA which involves lot of printing.
www.corvit.com
5-State Process Model
Broadly speaking the life of a process consist of CPU burst and I/O burst but
in reality
• A process may be waiting for an event to occur; e.g. a process has created
a child process and is waiting for it to return the result
• A process may be waiting for a resource which is not available at this time
• Process has gone to sleep for some time
So generally speaking a Process may be in one of the following five states:
new: The process is being created (Disk to Memory)
ready: The process is in main memory waiting to be assigned to a processor
running: Instructions are being executed
waiting: The process is waiting for some event to occur (I/O completion or
reception of a signal)
terminated: The process has finished execution
www.corvit.com
5-State Process Model
As a process executes, it
changes state:
– new: The process is being
created
– ready: The process is waiting to
run
– running: Instructions are being
executed
– waiting: Process waiting for
some event to occur
– terminated: The process has
finished execution
www.corvit.com
Process Scheduling Queues
• Job Queue – When a process enters the system it is put into a
job Queue. This queue consists of all processes in the system
• Ready Queue – This queue consists of processes that are
residing in main memory and are ready and waiting to
execute. It is generally stored as a link list
• Device Queues – When the process is allocated the CPU, it
executes for a while and eventually quits as it may need an
I/O. The list of processes waiting for a particular I/O device is
called a device queue. Each device has its own device queue
• A process in its life time will be migrating from one Q to
another Q
www.corvit.com
Queuing Diagram
www.corvit.com
Orphan vs Zombie Process
Orphan Process Zombie Process
www.corvit.com
Threads
Every process has two characteristics:
• Resource ownership process includes a virtual address space
to hold the process image
• Scheduling follows an execution path that may be interleaved
with other processes
These two characteristics are treated independently by the
operating system. The unit of resource ownership is referred to as
a process, while the unit of dispatching is referred to as a thread
A thread is an execution context that is independently scheduled,
but shares a single addresses space with other threads of the
same process
www.corvit.com
Threads
Single Threaded Process Multithreaded Process
www.corvit.com
Threads
www.corvit.com
Threads vs Process
Similarities Differences
www.corvit.com
Scheduling Algorithms
• FCFS
• SJF
• Priority
• Round Robin
www.corvit.com
Name some OSs
• UNIX
• Linux
• Windows
• Sun Solaris
• Mac
• Android
• IOS
• Symbian
• BlackBerry
www.corvit.com
Linux History
UNIX
• In 1969 at Bell Laboratories UNIX was deployed.
• Simple and elegant.
• Written in the C programming language instead of in assembly code.
• Able to recycle code.
• The code recycling features were very important. Until then, all
commercially available computer systems were written in a code
specifically developed for one system. UNIX on the other hand needed
only a small piece of that special code, which is now commonly named
the kernel. This kernel is the only piece of code
that needs to be adapted for every specific system and forms the base of
the UNIX system. The operating system and all other functions were built
around this kernel and written in a higher programming language, C
www.corvit.com
Linux History
www.corvit.com
Distributions
• A Linux distribution includes a kernel and a collection of
applications. – Linux kernel – Applications (GNU, etc) – Desktop
(Gnome, KDE, etc.)
• Dozens of distributions available to suit a large variety of
needs. – RedHat, SUSE, Ubuntu, CentOS, Debian
www.corvit.com
Pros & Cons
Pros Cons
• Open Source • There are far too many
• Kernel is free different distributions
• Linux was made to keep on • Linux is not very user friendly
running and confusing for beginners
• Linux is secure and versatile
• Linux is scalable
www.corvit.com
Configuring Ubuntu for Lab
• Install Ubuntu on your local machine as the host OS.
https://
ubuntu.com/tutorials/install-ubuntu-desktop#1-overview
• Install Ubuntu on WSL on Windows 10
https://
ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-
10#1-overview
• Install a Hypervisor (Virtual Box) on your windows
machine and install Ubuntu image on the hypervisor.
https
://www.toptechskills.com/linux-tutorials-courses/how-to-in
stall-ubuntu-1804-bionic-virtualbox
/
www.corvit.com
Virtualization
• Virtualization is a framework or
methodology of dividing the
resources of a computer system
into multiple execution
environments
• Virtualization is a Technology
that transforms hardware into
software
• Virtualization allows to run
multiple operating systems as
virtual machines. Each copy of
an operating system is installed
in to a virtual machine.
www.corvit.com
Virtualization
• A stack: combination of infrastructure, OS, and
applications required to support a service.
www.corvit.com
Virtualization Solves Problem
• Servers become as easy to maintain as software.
– It’s easier to move software around than physical
servers.
• No need to purchase a separate server for each user or
team because virtualization provides partitioning.
www.corvit.com
Virtualization
• Host machine: physical server that supports multiple
virtual machines.
• Virtual machine: virtualized server instance running on a
host machine (also known as an instance or a workload).
• Host OS: operating system running on a bare-metal server.
• Guest OS: operating system running on a virtual machine.
• Hypervisor: Software that emulates and manages the
communication between virtual machines and the physical
server.
www.corvit.com
Virtualization Types
Hardware Virtualization OS Partitioning
• Part of physical server • Host (or guest) operating
dedicated to a specific stack. system can partition out
• Big expensive mainframe-type processes, memory, and
systems scheduling to emulate a
separate OS environment.
• Separate OS environments all
use same kernel. If host is
Linux then all “guests” are
Linux.
• Example: Docker containers
www.corvit.com
Hypervisor Types
Two types available:
Type 1 Hypervisor
• Runs on top of the bare-metal server and sits between hardware
and operating systems in the stacks.
• Examples: VMWare ESX, Microsoft Virtual Server, Xen
Type 2 Hypervisor
• Runs on top of an operating system.
• Easy installation (no special hypervisor or storage required).
• Example: Oracle VirtualBox, VMWare Fusion
www.corvit.com
Type 1 vs Type 2 Hypervisor
www.corvit.com
The Traditional Server Concept
www.corvit.com
And if something goes wrong
www.corvit.com
The Traditional Server Concept
Pros Cons
• Easy to conceptualize • Expensive to acquire and maintain
• Fairly easy to deploy hardware
• Easy to backup • Not very scalable
• Virtually any • Difficult to replicate
application/service can be run • Redundancy is difficult to implement
from this type of setup • Vulnerable to hardware outages
• In many cases, processor is under-
utilized
www.corvit.com
The Virtual Server Concept
www.corvit.com