KEMBAR78
OS & System Programming Course | PDF | Operating System | Bios
0% found this document useful (0 votes)
42 views109 pages

OS & System Programming Course

Uploaded by

aryakadam348
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views109 pages

OS & System Programming Course

Uploaded by

aryakadam348
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 109

Operating System and system Programming (OSSP)

By Prof. Mandar K. Mokashi


Department of IT, VIIT Pune

Department of Information Technology, VIIT, Pune-48


Course Objectives
• To introduce basic concepts and functions of modern operating systems.
• To understand the concept of process and thread management.
• To understand the scheduling of processes and threads & understand the concept of
concurrency control.
• To understand the concept of I/O and File management.
• To understand various Memory Management techniques.
• To study and understand compiler design

Department of Information Technology, VIIT, Pune-48


Syllabus

• Unit I-Overview of Operating System


• Operating System Objectives and Functions, The Evolution of Operating Systems,
Developments Leading to Modern Operating Systems, Virtual Machines. BASH Shell
scripting: Basic shell commands, shell as a scripting language.

• Unit II - Process Description and Control


• Process: Concept of a Process, Process States, Process Description, Process Control (Process
creation, Waiting for the process/processes, Loading programs into processes and Process
Termination), Execution of the Operating System. Threads: Processes and Threads, Concept
of Multithreading, Types of Threads, Thread programming Using Pthreads. Scheduling:
Types of Scheduling, Scheduling Algorithms, and Thread Scheduling

Department of Information Technology, VIIT, Pune-48


Syllabus

• Unit III- Concurrency Control


• Process/thread Synchronization and Mutual Exclusion: Principles of Concurrency,
Requirements for Mutual Exclusion, Mutual Exclusion: Hardware Support, Operating System
Support (Semaphores and Mutex), Programming Language Support (Monitors). Classical
synchronization problems: Readers/Writers Problem, Producer and Consumer problem,
Interprocess communication (Pipes, shared memory: system V). Deadlock: Principles of
Deadlock, Deadlock Modeling, Strategies to deal with deadlock: The Ostrich Algorithm,
Deadlock Prevention, Deadlock Avoidance, Deadlock detection and recovery, An Integrated
Deadlock Strategy, Example: Dining Philosophers Problem.

Department of Information Technology, VIIT, Pune-48


Syllabus
• Unit IV- Memory Management
• Memory Management: Memory Management Requirements, Memory Partitioning: Fixed
Partitioning, Dynamic Partitioning, Buddy System, Relocation, Paging, Segmentation. Virtual
Memory: Hardware and Control Structures, Operating System Software.
• Unit V-Input / Output And File Management
• I/O Management and Disk Scheduling: I/O Devices, Organization of the I/O Function,
Operating System Design Issues, I/O Buffering, Disk Scheduling(FIFO, SSTF, SCAN, C-SCAN,
LOOK, C-LOOK), Disk Cache. File Management: Overview, File Organization and Access, File
Directories, File Sharing, Record Blocking, Secondary Storage Management.
• Unit VI – Study of Linux Operating System
• Linux Design Principles, Linux Booting Process, Kernel Modules, Process Management,
Scheduling, Memory Management, File Systems, Input and Output, Inter-process
Communication.

Department of Information Technology, VIIT, Pune-48


Static View of System Components

Department of Information Technology, VIIT, Pune-48


The Structure of Computer Systems
Accessing computer resources is divided into layers.
Each layer is isolated and only interacts directly with the layer below or
above it.
If we install a new hardware device
✔ No need to change anything about the user/applications.
✔ However, need to make changes to the operating system.
✔ Need to install the device drivers that the operating system will use to
control the new device.
If we install a new software application
✔ No need to make any changes to your hardware.
✔ But need to ensure the application is supported by the operating system
✔ user will need to learn how to use the new application.
If we change the operating system
✔ Need to make sure that both applications and hardware will be
compatible with the new operating system.
Department of Information Technology, VIIT, Pune-48
Computer System Components

1. Hardware – provides basic computing resources (CPU, Memory, I/O


devices, Communication devices).
2. Operating System – controls and coordinates use of the hardware
among various application programs
for various users.
1. System & Application Programs – ways in which the system resources
are used to solve computing problems of the users (Word processors,
Compilers, Web browsers, Database systems, Video games).
2. Users – (People, Machines, other computers, programs).

Department of Information Technology, VIIT, Pune-48


Hierarchical view of computer system

Department of Information Technology, VIIT, Pune-48


CPU – Central Processing Unit

• This is the brain of computer.


• It performs all of the calculations.
• In order to do its job, the CPU needs commands to perform, and data to work with.
• The instructions and data travel to and from the CPU on the system bus.
• The operating system provides rules for how that information gets back and
forth, and how it will be used by the CPU.

Department of Information Technology, VIIT, Pune-48


RAM – Random Access Memory

• This is like a desk, or a workspace, where your computer temporarily stores all of the
information (data) and instructions (software or program code) that it is currently using.
• Each RAM chip contains millions of address spaces.
• Each address space is the same size, and has its own unique identifying number (address).
• The operating system provides the rules for using these memory spaces, and controls
storage and retrieval of information from RAM.
• Device drivers for RAM chips are included with the operating system.

• Problem: If RAM needs an operating system to work, and an operating system needs RAM
in order to work, how does your computer activate its RAM to load the operating system?

Department of Information Technology, VIIT, Pune-48


What is Operating System?

• An operating system is a program that acts as an interface between the software and the
computer hardware.
• It is an integrated set of specialized programs used to manage overall resources and
operations of the computer.
• It is a specialized software that controls and monitors the execution of all other programs
that reside in the computer, including application programs and other system software.

Department of Information Technology, VIIT, Pune-48


What is an Operating System ?

• A modern computer consists of:


– One or more processors
– Main memory
– Disks
– Printers
– Various input/output devices.
• Managing all these varied components requires a layer of software – the Operating
System (OS).

Department of Information Technology, VIIT, Pune-48


What is Operating System?

• Computer System = Hardware + Software


• Software = Application Software + System Software(OS)
• An Operating System is a system Software that acts as an intermediary/interface
between a user of a computer and the computer hardware.
• Operating system goals:
– Execute and Control user/application programs.
– Make the computer system convenient to use.
– Ease the solving of user problems.
– Use the computer hardware in an efficient manner.

Department of Information Technology, VIIT, Pune-48


Where does the OS fit in?

Department of Information Technology, VIIT, Pune-48


Operating System Mode

❖ The User Mode is concerned


with the actual interface
between user and the system.
❖ It controls things like running
applications and accessing
files.

❖ The Kernel Mode is concerned with everything


running in the background.
❖ It controls things like accessing system
resources, controlling hardware functions and
processing the program instructions.
❖ System calls are used to change mode
from User to Kernel.

Department of Information Technology, VIIT, Pune-48


Kernel
Kernel is a software code that reside in central core of OS. It has complete control
over the system.
When the system boots, kernel is first part of OS to load in main memory.
Kernel remains in main memory for entire duration of computer session. The kernel
code is usually loaded in to protected area of memory.
Kernel performs it’s task like executing processes and handling interrupts in kernel
space.
User performs it’s task in user area of memory.
This memory separation is made in order to prevent user data and kernel data from
interfering with each other.
Kernel does not interact directly with user, but it interacts using SHELL and other
programs and hardware.

Department of Information Technology, VIIT, Pune-48


Kernel cont…
Kernel includes:-
1. Scheduler: It allocates the Kernel’s processing time to various processes.
2. Supervisor: It grants permission to use computer system resources to each
process.
3. Interrupt handler : It handles all requests from the various hardware
devices which compete for kernel services.
4. Memory manager : allocates space in memory for all users of kernel
service.
kernel provides services for process management, file management, I/O
management, memory management.
System calls are used to provide these type of services.

Department of Information Technology, VIIT, Pune-48


System Call

• System call is the programmatic way in which a computer program/user application


requests a service from the kernel of the operating system on which it is executed.
• Application program is just a user-process. Due to security reasons , user applications
are not given access to privileged resources (the ones controlled by OS).
• When they need to do any I/O or have some more memory or spawn a process or wait
for signal/interrupt, it requests operating system to facilitate all these. This request is
made through System Call.
• System calls are also called software-interrupts.

Department of Information Technology, VIIT, Pune-48


Starting an Operating System(Booting)

✔ Power On Switch sends electricity to the motherboard on a ✔ BIOS will then look for a small sector at the very beginning of your
wire called the Voltage Good line. primary hard disk called MBR.
✔ If the power supply is good, then the BIOS (Basic ✔ The MBR contains a list, or map, of all of the partitions on your
Input/Output System) chip takes over. computer‘s hard disk (or disks).
✔ In Real Mode, CPU is only capable of using approximately ✔ After the MBR is found the Bootstrap Loader follows basic instructions
1 MB of memory built into the motherboard. for starting up the rest of the computer, including the operating system.
✔ The BIOS will do a Power-On Self Test (POST) to make ✔ In Early Kernel Initialization stage, a smaller core of the Kernel is
sure that all hardware are working. activated.
✔ This core includes the device drivers needed to use computer‘s RAM
chips.

Department of Information Technology, VIIT, Pune-48


BIOS

• BIOS firmware is stored in a ROM/EPROM (Erasable Programmable Read-Only Memory)


chip known as firmware on the PC motherboard.
• BIOS can be accessed during the initial phases of the boot procedure by pressing del, F2
or F10.
• Finally, the firmware code cycles through all storage devices and looks for a boot-loader.
(usually located in first sector of a disk which is 512 bytes)
• If the boot-loader is found, then the firmware hands over control of the computer to it.

Department of Information Technology, VIIT, Pune-48


UEFI
• UEFI stands for Unified Extensible Firmware Interface. It does the same job as a BIOS,
but with one basic difference: it stores all data about initialization and startup in an .efi
file, instead of storing it on the firmware.
• This .efi file is stored on a special partition called EFI System Partition (ESP) on the hard
disk. This ESP partition also contains the bootloader.
• UEFI was designed to overcome many limitations of the old BIOS, including:
UEFI supports drive sizes upto 9 zettabytes, whereas BIOS only supports 2.2 terabytes.
UEFI provides faster boot time.
UEFI has discrete driver support, while BIOS has drive support stored in its ROM, so updating BIOS
firmware is a bit difficult.
UEFI offers security like "Secure Boot", which prevents the computer from booting from
unauthorized/unsigned applications. This helps in preventing rootkits.
UEFI runs in 32bit or 64bit mode, whereas BIOS runs in 16bit mode. So UEFI is able to provide a GUI
(navigation with mouse) as opposed to BIOS which allows navigation only using the keyboard.

Department of Information Technology, VIIT, Pune-48


Functions of Operating System

Department of Information Technology, VIIT, Pune-48


1. Process Management

• A process is a program in execution.


• A process needs certain resources, including CPU time, memory, files, and I/O devices to
accomplish its task.
• Simultaneous execution leads to multiple processes. Hence creation, execution and
termination of a process are the most basic functionality of an OS
• If processes are dependent, than they may try to share same resources. thus task of process
synchronization comes to the picture.
• If processes are independent, then a due care needs to be taken to avoid their overlapping in
memory area.
• Based on priority, it is important to allow more important processes to execute first than
others.

Department of Information Technology, VIIT, Pune-48


2. Memory management

• Memory is a large array of words or bytes, each with its own address.
• It is a repository of quickly accessible data shared by the CPU and I/O devices.
• Main memory is a volatile storage device. When the computer is turned off, everything
stored in RAM will be erased automatically.
• In addition to the physical RAM installed in the computer, most modern OS allow the
computer to use a virtual memory system. Virtual memory allows the computer to use
part of a permanent storage device (such as a hard disk) as extra memory.
• The operating system is responsible for the following activities in connections with
memory management:
Keep track of which parts of memory are currently being used and by whom.
Decide which processes to load when memory space becomes available.
Allocate and de-allocate memory space as needed.

Department of Information Technology, VIIT, Pune-48


3. File Management

• A file is a collection of related information defined by its creator.


• File systems provide the conventions for the encoding, storage and
management of data on a storage device such as a hard disk.
FAT12 (floppy disks)
FAT16 (DOS and older versions of Windows)
FAT32 (older versions of Windows)
NTFS (newer versions of Windows)
EXT3 (Unix/Linux)
HFS+ (Max OS X)
• The operating system is responsible for the following activities in connections with file
management:
✦ File creation and deletion.
✦ Directory creation and deletion.
✦ Support of primitives for manipulating files and directories.
✦ Mapping files onto secondary storage.
✦ File backup on stable (nonvolatile) storage media.
Department of Information Technology, VIIT, Pune-48
4. Device Management or I/O Management
• Device controllers are components on the motherboard that act as an interface between the
CPU and the actual device.
• Device drivers, which are the operating system software components that interact with the
device’s controllers.
• A special device (inside CPU) called the Interrupt Controller handles the task of receiving
interrupt requests and prioritizes them to be forwarded to the processor.
• Deadlocks can occur when two (or more) processes have control of different I/O resources
that are needed by the other processes, and they are unwilling to give up control of the
device.
• It performs the following activities for device management.
Keeps tracks of all devices connected to system.
Designates a program responsible for every device known as Input/output controller.
Decides which process gets access to a certain device and for how long.
Allocates devices in an effective and efficient way.
Deallocates devices when they are no longer required.

Department of Information Technology, VIIT, Pune-48


5. Security & Protection

• The operating system uses password protection to protect user data and similar other
techniques.
• It also prevents unauthorized access to programs and user data by assigning access
right permission to files and directories.
• The owners of information stored in a multiuser or networked computer system may
want to control use of that information, concurrent processes should not interfere
with each other. This is facilitated by the OS

Department of Information Technology, VIIT, Pune-48


6. User Interface Mechanism

• A user interface (UI) controls how you enter data and instructions and how
information is displayed on the screen
• There are two types of user interfaces
1. Command Line Interface
2. Graphical user Interface

Department of Information Technology, VIIT, Pune-48


1. Command-line interface

• In a command-line interface, a user types commands represented by short keywords


or abbreviations or presses special keys on the keyboard to enter data and instructions

Department of Information Technology, VIIT, Pune-48


2. Graphical User Interface

• With a graphical user interface (GUI), you interact with menus and visual images

Department of Information Technology, VIIT, Pune-48


History of Operating System

• A major OS will evolve over time for a number of reasons:

Department of Information Technology, VIIT, Pune-48


History of Operating System

❖ The First Generation (1940's to early 1950's)


No Operating System
All programming was done in absolute machine language, often by wiring up plug-boards to
control the machine’s basic functions.
❖ The Second Generation (1955-1965)
First operating system was introduced in the early 1950's.It was called GMOS
Created by General Motors for IBM's machine the 701.
Single-stream batch processing systems
❖ The Third Generation (1965-1980)
Introduction of multiprogramming
Development of Minicomputer
❖ The Fourth Generation (1980-Present Day)
Development of PCs
Birth of Windows/MaC OS

Department of Information Technology, VIIT, Pune-48


History of Operating System
• First Generation (Serial Processing)
• Time Period: The 1940s and 1950s marked the start of electronic computers. They were the new trend,
replacing old mechanical ones.
• Size and Cost: These early computers were huge! And they came with a big price tag too.
• Basic Functions: Despite their size and cost, they could only do simple tasks.
• No Operating System: Imagine a computer without an operating system! That’s how they were. They just
did tasks one by one.
• Serial Processing: This means they finish one task before starting the next. No multitasking here!
• Limitations of First Generation
• Wasted Power: The main computer brain, the CPU, often just sat there doing nothing. It waited a lot,
especially during tasks like reading data, which wasted its power.
• One Task at a Time: These systems were like a person who can’t multitask. They could only handle one job
at a time, making things slow.
• Long Wait Times: Imagine giving someone a job and waiting ages to see the result. That’s how these
systems were. You’d give them a task, and it used to take took too long to get the outcome.

Department of Information Technology, VIIT, Pune-48


History of Operating System
• Second Generation (Batch System)
• Due to the inefficiencies of serial processing, the need for a more optimized approach became evident. This led
to the development of a batch-processing system. This era (1950-60) is called the second generation of OS
• In a batch system, similar tasks (or jobs) are grouped into batches and then processed sequentially without any
user interaction.
• The goal was to automate the processing of jobs and minimize the setup time.
• A scripting language, Job Control Language (JCL), was introduced to manage these batches.
• It allows operators to specify the sequence of jobs to be executed.
• Advantages
• The system optimizes the processing sequence by grouping similar tasks, reducing the overhead and setup time
between jobs.
• It allows for automated processing of tasks, i.e., reduces the need for manual intervention.
• The system could better utilize CPU and minimum idle time by processing tasks in batches.
• Limitations
• It lacks real-time user interaction, i.e., users have to wait for the entire batch to be processed.
• If the batches contain multiple tasks, giving output takes a longer time.
• Once the batch is processed, corrections can’t be done.

Department of Information Technology, VIIT, Pune-48


History of Operating System
• Third Generation (Multi-Programmed Batch System)
• In the previous two generations, the systems ran jobs one at a time in sequence, which was inefficient
because the CPU had to wait for I/O operations to complete. To overcome this, multiprogramming was
introduced in the next generations of operating systems.
• Multiprogramming allows multiple jobs to reside in the main memory at once, i.e., the CPU could switch to
another job if one job needs to wait for I/O operation. Due to multi-programming CPU could process more
jobs in a given amount of time.
• Since multiple jobs are done at once, there was a need for more advanced memory management. These
memory needs led to the development of concepts such as memory partitioning, paging, and
segmentation.
• Since multiple jobs are done at a time, it is important to decide which job to execute first, second, or last.
Algorithms like First-Come-First-Serve, Shortest Job Next (SJN), and Round Robin are developed.
• The complexity of the OS was increased, and system utilities were developed to help manage files, devices,
and other system resources.
• Operating systems were accompanied by hardware like Integrated Circuit, which allowed for smaller,
faster, and more reliable computers.

Department of Information Technology, VIIT, Pune-48


History of Operating System

• Fourth Generation (Time-Sharing Operating System)


• The fourth-generation operating system was more commonly associated with programming languages
that were close to human language and often used for database-related tasks.
• The fourth generation has features like:
• GUI, that allows users to interact with the system using windows, icons, and menus.
• Ability to run multiple applications simultaneously.
• Built-in capabilities to connect to and function on networks, including the Internet.
• Automatically recognize and configure hardware devices.
• Advanced security mechanism to protect against malware, unauthorized access.
• Compatibility with a wide range of hardware devices and architecture.
• The OS allocates a small time slice or quantum to each task.

Department of Information Technology, VIIT, Pune-48


Types of Operating Systems

• Batch Operating System


• Multiprogramming Operating System
• Time-Sharing OS
• Multiprocessing OS
• Distributed OS
• Network OS
• Real Time OS
• Embedded OS

Department of Information Technology, VIIT, Pune-48


1. Batch Operating System

• The users of this type of operating system does not interact with the computer directly.
• Each user prepares the job on an off-line device like punch cards and submits it to the
computer operator
• The operator takes similar jobs having the same requirement and group them into batches.

Department of Information Technology, VIIT, Pune-48


1. Batch Operating System cont..

Advantages of Batch Operating System:


Processors of the batch systems know how long the job would be when it is in queue
Multiple users can share the batch systems
The idle time for the batch system is very less
It is easy to manage large work repeatedly in batch systems
Disadvantages of Batch Operating System:
The computer operators should be well known with batch systems
Batch systems are hard to debug
It is sometimes costly
The other jobs will have to wait for an unknown time if any job fails
Examples of Batch based Operating System:
IBM's MVS

Department of Information Technology, VIIT, Pune-48


2. Multiprogramming Operating System:

• This type of OS is used to execute more than one jobs simultaneously by a single processor.
• It increases CPU utilization by organizing jobs so that the CPU always has one job to execute.
• Multiprogramming operating systems use the mechanism of job scheduling and CPU
scheduling.

Department of Information Technology, VIIT, Pune-48


2. Multiprogramming Operating System:

Department of Information Technology, VIIT, Pune-48


2. Multiprogramming Operating System:

Table - Effects of Multiprogramming on Resource Utilization

Department of Information Technology, VIIT, Pune-48


3. Time-Sharing Operating Systems

• Each task is given some time to execute so that all the tasks work smoothly.
• These systems are also known as Multi-tasking Systems.
• The task can be from a single user or different users also.
• The time that each task gets to execute is called quantum.
• After this time interval is over OS switches over to the next task.

Department of Information Technology, VIIT, Pune-48


3. Time-Sharing Operating Systems cont..
• Advantages of Time-Sharing OS:
Each task gets an equal opportunity
Fewer chances of duplication of software
CPU idle time can be reduced

• Examples of Time-Sharing Oss


Multics, Unix, etc.

Department of Information Technology, VIIT, Pune-48


4. Multiprocessor operating systems

• Multiprocessor operating systems are also known as parallel OS or tightly coupled OS.
• Such operating systems have more than one processor in close communication that
sharing the computer bus, the clock and sometimes memory and peripheral devices.
• It executes multiple jobs at the same time and makes the processing faster.
• It supports large physical address space and larger virtual address space.
• If one processor fails then other processor should retrieve the interrupted process
state so that the execution of process can continue.

Department of Information Technology, VIIT, Pune-48


5. Distributed Operating System

• It is a system software over a collection of independent software, networked,


communicating, and physically separate computational nodes.
• They handle jobs which are serviced by multiple CPUs.
• Each individual node holds a specific software subset of the global aggregate operating
system.
• These are referred to as loosely coupled systems.
• Examples:- Locus, DYSEAC

Department of Information Technology, VIIT, Pune-48


6. Network Operating System

• These systems run on a server and provide the capability to manage data,
users, groups, security, applications, and other networking functions.
• These types of operating systems allow shared access of files, printers,
security, applications, and other networking functions over a small private
network.
• The “ other" computers are called client computers, and each computer
that connects to a network server must be running client software
designed to request a specific service.
• popularly known as tightly coupled systems.

Department of Information Technology, VIIT, Pune-48


6. Network Operating System

Advantages of Network Operating System:


Highly stable centralized servers
Security concerns are handled through servers
New technologies and hardware up-gradation are easily integrated into the system
Server access is possible remotely from different locations and types of systems
Disadvantages of Network Operating System:
Servers are costly
User has to depend on a central location for most operations
Maintenance and updates are required regularly
Examples of Network Operating System are:
Microsoft Windows Server 2003/2008/2012, UNIX, Linux, Mac OS X, Novell NetWare, and BSD,
etc.

Department of Information Technology, VIIT, Pune-48


7. Real-Time Operating System

• These types of OSs serve real-time systems.


• The time interval required to process and respond to inputs is very small.
• This time interval is called response time.
• Real-time systems are used when there are time requirements that are
very strict like
missile systems,
air traffic control systems,
robots, etc.

Department of Information Technology, VIIT, Pune-48


8. Embaded Operating System

• An embedded operating system is one that is built into the circuitry of an electronic
device.
• Embedded operating systems are now found in automobiles, bar-code scanners, cell
phones, medical equipment, and personal digital assistants.
• The most popular embedded operating systems for consumer products, such as PDAs,
include the following:
Windows XP Embedded
Windows CE .NET:- it supports wireless communications, multimedia and Web
browsing. It also allows for the use of smaller versions of Microsoft Word, Excel,
and Outlook.
Palm OS:- It is the standard operating system for Palm-brand PDAs as well as
other proprietary handheld devices.
Symbian:- OS found in “ smart” cell phones from Nokia and Sony Ericsson

Department of Information Technology, VIIT, Pune-48


Popular types of OS
• Desktop Class
❖ Windows
❖ OS X
❖ Unix/Linux
❖ Chrome OS
• Server Class
❖ Windows Server
❖ Mac OS X Server
❖ Unix/Linux
• Mobile Class
❖ Android
❖ iOS
❖ Windows Phone

Department of Information Technology, VIIT, Pune-48


Desktop Class Operating Systems:-

• Platform: the hardware required to run a particular operating system


– Intel platform (IBM-compatible)
• Windows
• DOS
• UNIX
• Linux
– Macintosh platform
• Mac OS
– iPad and iPhone platform
• iOS

Department of Information Technology, VIIT, Pune-48


Ms-DOS

• Single User Single Tasking OS.


• It had no built-in support for networking, and users had to manually install drivers any
time they added a new hardware component to their PC.
• DOS supports only 16-bit programs.
• Command line user interface.
• So, why is DOS still in use? Two reasons are its size and simplicity. It does not require
much memory or storage space for the system, and it docs not require a powerful
computer.

Department of Information Technology, VIIT, Pune-48


Microsoft Windows

• The graphical Microsoft operating system designed for Intel-platform


desktop and notebook computers.
• Best known, greatest selection of applications available.
• Current editions include Windows 7, 8, 8.1 and 10.

Department of Information Technology, VIIT, Pune-48


Mac OS

• User-friendly, runs on Mac hardware. Many applications available.


• Current editions include: Sierra, High Sierra, Mojave, Catalina & Big Sur—Version
XI(Released in Nov 2020)

Department of Information Technology, VIIT, Pune-48


Linux

• Linux: An open-source, cross-platform operating system that runs on


desktops, notebooks, tablets, and smartphones.
– The name Linux is a combination Linus (the first
name of the first developer) and UNIX (another
operating system.)
• Users are free to modify the code, improve it, and redistribute it,
• Developers are not allowed to charge money for the Linux kernel itself
(the main part of the operating system), but they can charge money for
distributions (distros for short).

Department of Information Technology, VIIT, Pune-48


Google Chrome OS

• Chrome OS. Is a popular thin client operating system.


• Thin client A computer with minimal hardware, designed for a specific task.
For example, a thin web client is designed for using the Internet.

Department of Information Technology, VIIT, Pune-48


Server Operating Systems

• Windows Server
– Familiar GUI interface for those experienced with Windows
• UNIX
– Very mature server capabilities, time-tested, large user
community, stable
• Linux
– Free, customizable, many free services and utilities available

Department of Information Technology, VIIT, Pune-48


Windows Server

Department of Information Technology, VIIT, Pune-48


UNIX

Department of Information Technology, VIIT, Pune-48


Tablet and Phone Operating Systems

• System-on-chip (SoC): An operating system that comes preinstalled on a


chip on a portable device such as a smartphone.
• Popular SoC operating systems:
▪ iOS: for iPad, iPhone
▪ Android: for a variety of tablets and smartphones
• Downloadable applications (apps) from an App store, for example:
▪ Apple App Store
▪ Google Play Store

Department of Information Technology, VIIT, Pune-48


Android

• Android, a popular OS for smartphones and tablets, is based on Linux Kernel.


Developed by Google
• Current versions include:
Android 8 Oreo
Android 9 Pie
Android 10
Android 11

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System
1. Open Source
As it is open-source, its source code is easily available.
Anyone having programming knowledge can customize the operating system.
One can contribute, modify, distribute, and enhance the code for any purpose.
2. Security
The Linux security feature is the main reason that it is the most favourable option for
developers.
It is not completely safe, but it is less vulnerable than others.
Each application needs to authorize by the admin user.
Linux systems do not require any antivirus program.
3. Free
Certainly, the biggest advantage of the Linux system is that it is free to use.
We can easily download it, and there is no need to buy the license for it.
It is distributed under GPL (General Public License).
Comparatively, we have to pay a huge amount for the license of the other OS

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System
4. Lightweight
The requirements for running Linux are much less than other operating system
In Linux, the memory footprint and disk space are also lower.
Generally, most of the Linux distributions required as little as 128MB of RAM around the
same amount for disk space.

5. Stability
Linux is more stable than other operating systems.
Linux does not require to reboot the system to maintain performance levels.
It rarely hangs up or slow down. It has big up-times.

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System
6. Performance
Linux system provides high performance over different networks.
It is capable of handling a large number of users simultaneously.
7. Flexibility
Linux operating system is very flexible.
It can be used for desktop applications, embedded systems, and server applications too.
It also provides various restriction options for specific computers.
We can install only necessary components for a system.
8. Software Updates
In Linux, the software updates are in user control. We can select the required updates.
There are large number of system updates available.
These updates are much faster than other operating systems.
So, the system updates can be installed easily without facing any issue.

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System

9. Distributions/ Distros
There are many Linux distributions available in the market.
It provides various options and flavors of Linux to the users.
We can choose any distros according to our needs.
Some popular distros are Ubuntu, Fedora, Debian, Linux Mint, Arch Linux,
For the beginners, Ubuntu and Linux Mint would be useful.
Debian and Fedora would be good choices for proficient programmers.
10. Graphical User Interface
Linux is a command-line based OS but it provides an interactive user interface like Windows.

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System
12. Suitable for programmers
It supports almost all of the most used programming languages such as C/C++, Java, Python, Ruby,
and more.
Further, it offers a vast range of useful applications for development.
The programmers prefer the Linux terminal over the Windows command line.
The package manager on Linux system helps programmers to understand how things are done.
Bash scripting is also a functional feature for the programmers.
It also provides support for SSH, which helps in managing the servers quickly.
13. Community Support
Linux provides large community support.
We can find support from various sources.
There are many forums available on the web to assist users.
Further, developers from the various open source communities are ready to help us.

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System
14. Privacy
Linux always takes care of user privacy as it never takes much private data from the user. Comparatively,
other operating systems ask for the user's private data.
15. Networking
Linux facilitates with powerful support for networking. The client-server systems can be easily set to a
Linux system. It provides various command-line tools such as ssh, ip, mail, telnet, and more for
connectivity with the other systems and servers. Tasks such as network backup are much faster than
others.
16. Compatibility
Linux is compatible with a large number of file formats as it supports almost all file formats.
17. Installation
Linux installation process takes less time than other operating systems such as Windows. Further, its
installation process is much easy as it requires less user input. It does not require much more system
configuration even it can be easily installed on old machines having less configuration.

Department of Information Technology, VIIT, Pune-48


Advantage of Linux Operating System

18. Multiple Desktop Support


Linux system provides multiple desktop environment support for its enhanced use. The desktop
environment option can be selected during installation. We can select any desktop environment such as
GNOME (GNU Network Object Model Environment) or KDE (K Desktop Environment) as both have
their specific environment.
19. Multitasking
It is a multitasking operating system as it can run multiple tasks simultaneously without affecting the
system speed.
20. Heavily Documented for beginners
There are many command-line options that provide documentation on commands, libraries, standards
such as manual pages and info pages. Also, there are plenty of documents available on the internet in
different formats, such as Linux tutorials, Linux documentation project, Serverfault, and more. To help
the beginners, several communities are available such as Ask Ubuntu, Reddit, and StackOverflow.

Department of Information Technology, VIIT, Pune-48


Virtual Machine

• Traditionally, applications have run directly on an OS on a PC or a server.


• Each PC or server would run only one OS at a time. Thus, the vendor had to rewrite parts of its
applications for each OS/platform they would run on.
• An effective strategy for dealing with this problem is known as virtualization
• Virtualization technology enables a single PC or server to simultaneously run multiple operating
systems.
• The VM approach (ex. VMware) maximizes the number of kinds of applications that a single
computer can handle.

Department of Information Technology, VIIT, Pune-48


Virtual Machine

Department of Information Technology, VIIT, Pune-48


What is Shell ?

• The shell is the outermost layer of operating system. Linux Shell is the interface between
Kernel and user.

• A shell is a special user program that provides an interface to the user to use operating
system services.
• Shell accepts human-readable commands from the user and converts them into something
which the kernel can understand.
• It is a command language interpreter that executes commands read from input devices such
as keyboards or from files.
• The shell gets started when the user logs in or starts the terminal.

Department of Information Technology, VIIT, Pune-48


UNIX Shell and Utilities

• Your interface to the operating


system is called a shell. User
• The shell is the outermost layer of
the operating system.
• Shells incorporate a programming Utilities Shell
language to control processes and
files, as well as to start and control
other programs.
• Ex. sh, bsh, csh, ksh, tcsh, wsh, bash Kernel
• Possible to switch between them
(chsh)

Hardware
Department of Information Technology, VIIT, Pune-48
What is Shell ?

Department of Information Technology, VIIT, Pune-48


Types of Shell
• There are two major types of shells −
• Bourne shell − If you are using a Bourne-type shell, the $ character is the default prompt.
– The Bourne Shell has the following subcategories −
– Bourne shell (sh)
– Korn shell (ksh)
– Bourne Again shell (bash)
– POSIX shell (sh)
• C shell − If you are using a C-type shell, the % is the default prompt.
– The different C-type shells follow −
– C shell (csh)
– TENEX/TOPS C shell (tcsh)

Department of Information Technology, VIIT, Pune-48


BASH Shell scripting

• A Shell provides you with an interface to the Unix system. It gathers input from you and
executes programs based on that input.
• When a program finishes executing, it displays the output.
• Shell is an environment in which we can run our commands, programs, and shell scripts.
• There are different flavors of a shell, just as there are different flavors of operating
systems.
• Each flavor of shell has its own set of recognized commands and functions.

Department of Information Technology, VIIT, Pune-48


BASH Shell scripting

• Shell Script consist of set of commands to perform some task.


• All the commands in shell script are executed sequentially.
• Shell Prompt
• The prompt, $, which is called the command prompt, is issued by the shell.
• While the prompt is displayed, you can type a command.
• Shell reads your input after you press Enter.
• It determines the command you want to execute by looking at the first word of your input.
• Following is a simple example of the date command, which displays the current date and
time −
$date Thu Jun 25 08:30:19 MST 2009

Department of Information Technology, VIIT, Pune-48


BASH Shell scripting

• To List out all the Shells


• $ cat/etc/shells <Enter>
• /bin/sh
• /bin/dash
• /bin/bash
• /bin/rbash

• These are few supported shells..To locate where bash is located use the following
command—
• $ which bash <enter>
• /bin/bash

Department of Information Technology, VIIT, Pune-48


Creating First bash script
$ touch hello.sh <enter> //creating new file
$ ls –al <enter> //list down all files
-rw-rw-r--

gedit
1. clear
2. #! /bin/bash //tells your terminal that when you run the script it should use bash to execute it.
3. echo “Hello world”
$ ./hello.sh //to execute the shell script

Department of Information Technology, VIIT, Pune-48


Basic Shell Commands

1). Displaying the file contents on the terminal:


•cat: It is used to concatenate the files. It gives the output on the standard output.
•more: It is a filter for paging through text one screenful at a time.
•less: It is used to viewing the files instead of opening the file.
•head : Used to print the first N lines of a file. It accepts N as input and the default value of N
is 10.
•tail : Used to print the last N-1 lines of a file. It accepts N as input and the default value of N
is 10.

Department of Information Technology, VIIT, Pune-48


Basic Shell Commands

2). File and Directory Manipulation Commands:


•Gedit : The gedit program is a graphical text editor that works well across many Unix-like
platforms. If you are not sure which editor to use, gedit is a good option.
•Pwd : The pwd command just shows the present working directory.
•mkdir : Used to create a directory if not already exist. It accepts the directory name as an input
parameter.
•cp : This command will copy the files and directories from the source path to the destination
path. It can copy a file/directory with the new name to the destination path. It accepts the
source file/directory and destination file/directory.
•mv : Used to move the files or directories. This command’s working is almost similar
to cp command but it deletes a copy of the file or directory from the source path.
•rm : Used to remove files or directories.
•touch : Used to create or update a a shell script file.

Department of Information Technology, VIIT, Pune-48


Basic Shell Commands

3). Extract, sort, and filter data Commands:


•grep : This command is used to search for the specified text in a file.
•sort : This command is used to sort the contents of files.
•wc : Used to count the number of characters, words in a file.

Department of Information Technology, VIIT, Pune-48


Basic Shell Commands
4). Basic Terminal Navigation Commands:
•ls : To get the list of all the files or folders.
•ls -l: Optional flags are added to ls to modify default behavior, listing contents in extended
form -l is used for “long” output
•ls -a: Lists of all files including the hidden files, add -a flag
•cd: Used to change the directory.
•du: Show disk usage.
•pwd: Show the present working directory.
•man: Used to show the manual of any command present in Linux.
•rmdir: It is used to delete a directory if it is empty.
•locate: It is used to locate a file in Linux System
•echo: This command helps us move some data, usually text into a file.
•df: It is used to see the available disk space in each of the partitions in your system.
Department of Information Technology, VIIT, Pune-48
Basic Shell Commands
5). File Permissions Commands: The chmod and chown commands are used to control
access to files in UNIX and Linux systems.
•chown : Used to change the owner of the file.
•chgrp : Used to change the group owner of the file.
•chmod : Used to modify the access/permission of a user.

Department of Information Technology, VIIT, Pune-48


Creating First bash script
• It will show the message “permission denied” as bydefault user have no execute
permission.

• To allow the user to execute the script, modify the permission-

$ chmod +x hello.sh
$ ls –al
-rwx-rwx-rx
$ ./hello.sh <enter>
Hello world

Department of Information Technology, VIIT, Pune-48


Comments in bash scripting

• Comments start with a # in bash scripting. This means that any line that begins with a # is
a comment and will be ignored by the interpreter.

• # This is an example comment


• # Both of these lines will be ignored by the interpreter

Department of Information Technology, VIIT, Pune-48


Variables and data types in Bash
• Variables let you store data. You can use variables to read, access, and manipulate data
throughout your script.
• There are no data types in Bash. In Bash, a variable is capable of storing numeric values,
individual characters, or strings of characters.
• In Bash, you can use and set the variable values in the following ways:
• 1. Assign the value directly:
• Country=India
• 2. Assign the value based on the output obtained from a program or command, using
command substitution.
• Note that $ is required to access an existing variable's value.
• newCountry= $Country
• This assigns the value of country to the new variable newCountry

Department of Information Technology, VIIT, Pune-48


Variables and data types in Bash
• Accessing Values
• To access the value stored in a variable, prefix its name with the dollar sign ($) −
• For example, the following script will access the value of defined variable NAME and print it
on STDOUT −
• NAME=“VIIT"
• echo $NAME //output - VIIT
• Read-only Variables
• Shell provides a way to mark variables as read-only by using the read-only command. After a
variable is marked read-only, its value cannot be changed.
• Ex- the following script generates an error while trying to change the value of NAME −
• NAME=“VIIT"
• readonly NAME
• NAME=“VIT“ //output - /bin/sh: NAME: This variable is read only.

Department of Information Technology, VIIT, Pune-48


Arrays in Bash
• Shell supports a different type of variable called an array variable.
• This can hold multiple values at the same time.
• Arrays provide a method of grouping a set of variables.
• Instead of creating a new name for each variable that is required, you can use a single
array variable that stores all the other variables.

• NAME1=“abc"
• NAME2=“lmn" NAME[0]=" abc "
• NAME3=“xyz" NAME[1]=“lmn"
• NAME4=“pqr" NAME[2]=“xyz"
• NAME5=“efg“ NAME[3]=“pqr"
NAME[4]=“efg"
• We can use a single array to store all the above mentioned names.
• array_name[index]=value

Department of Information Technology, VIIT, Pune-48


Arrays in Bash
• Accessing Array Values
• After you have set any array variable, you access it as follows −
• ${array_name[index]}
• Here array_name is the name of the array, and index is the index of the value to be
accessed. Following is an example to understand the concept −

• #!/bin/sh
• NAME[0]=" abc "
• NAME[1]=“lmn"
• NAME[2]=“xyz"
• NAME[3]=“pqr“ output - First Index:abc
• NAME[4]=“efg“ Second Index: lmn
• echo "First Index: ${NAME[0]}"
• echo "Second Index: ${NAME[1]}"

Department of Information Technology, VIIT, Pune-48


Arrays in Bash
• You can access all the items in an array in one of the following ways −

1) ${array_name[*]}
2) ${array_name[@]}

• #!/bin/sh
• NAME[0]=" abc "
• NAME[1]=“lmn"
• NAME[2]=“xyz"
• NAME[3]=“pqr"
• NAME[4]=“efg"
• echo "First Method: ${NAME[*]}“ output – First Method: abc lmn xyz pqr efg
• echo "Second Method: ${NAME[@]}“ Second Method: abc lmn xyz pqr efg

Department of Information Technology, VIIT, Pune-48


Gathering input
• Here we'll discuss some methods to provide input to our scripts.
• 1. Reading the user input and storing it in a variable
• We can read the user input using the read command.

• #!/bin/bash
• echo "Today is " `date`
• echo "\nenter the path to directory"
• read the_path
• echo "\nyour path has the following files and folders: "
• ls $the_path

Department of Information Technology, VIIT, Pune-48


Gathering input
• 2. Reading from a file
• This code reads each line from a file named input.txt and prints it to the terminal.

• while read line


• do
• echo $line
• done < input.txt

Department of Information Technology, VIIT, Pune-48


Displaying output
• Here we'll discuss some methods to receive output from the scripts.

• Printing to the terminal:


• echo "Hello, World!“
• This prints the text "Hello, World!" to the terminal.

• 2. Writing to a file:
• echo "This is some text." > output.txt
• This writes the text "This is some text." to a file named output.txt.
• Note that the >operator overwrites a file if it already has some content.

Department of Information Technology, VIIT, Pune-48


Append
• 3. Appending to a file:
• echo "More text." >> output.txt

• This appends the text "More text." to the end of the file output.txt.

Department of Information Technology, VIIT, Pune-48


Basic Operators in BASH
• Arithmetic Operators
• Relational Operators
• Boolean Operators
• String Operators

• val=`expr 2 + 2`
• echo "Total value : $val“ output - Total value : 4

Department of Information Technology, VIIT, Pune-48


Arithmatic Operators in BASH
Assume variable a holds 10 and variable b holds 20 then −
Operator Description Example
+ (Addition) Adds values on either side of the operator `expr $a + $b` will give 30
- (Subtraction) Subtracts right hand operand from left hand operand `expr $a - $b` will give -10
* (Multiplication) Multiplies values on either side of the operator `expr $a * $b` will give 200
/ (Division) Divides left hand operand by right hand operand `expr $b / $a` will give 2
% (Modulus) Divides left hand operand by right hand operand and returns `expr $b % $a` will give 0
remainder
= (Assignment) Assigns right operand in left operand a = $b will assign value of b into a
== (Equality) Compares two numbers, if both are same then returns true. [ $a == $b ] will return false.

!= (Not Equality) Compares two numbers, if both are different then returns [ $a != $b ] will return true.
true.
All the conditional expressions should be inside square braces with spaces around them, for
example [ $a == $b ] is correct whereas, [$a==$b] is incorrect.
Department of Information Technology, VIIT, Pune-48
Relational Operators in BASH
Assume variable a holds 10 and variable b holds 20 then −
Opera Description Example
tor
-eq Checks if the value of two operands are equal or not; if yes, then the condition [ $a -eq $b ] is not true.
becomes true.
-ne Checks if the value of two operands are equal or not; if values are not equal, then
[ $a -ne $b ] is true.
the condition becomes true.
-gt Checks if the value of left operand is greater than the value of right operand; if yes,
[ $a -gt $b ] is not true.
then the condition becomes true.
-lt Checks if the value of left operand is less than the value of right operand; if yes,
[ $a -lt $b ] is true.
then the condition becomes true.
-ge Checks if the value of left operand is greater than or equal to the value of right
[ $a -ge $b ] is not true.
operand; if yes, then the condition becomes true.
-le Checks if the value of left operand is less than or equal to the value of right
operand; if yes, then the condition becomes true. [ $a -le $b ] is true.

Department of Information Technology, VIIT, Pune-48


Boolean Operators in BASH
Assume variable a holds 10 and variable b holds 20 then −

Operator Description Example


! This is logical negation. This inverts a true condition
[ ! false ] is true.
into false and vice versa.
-o This is logical OR. If one of the operands is true, then [ $a -lt 20 -o $b -gt 100 ] is true.
the condition becomes true.
-a This is logical AND. If both the operands are true,
then the condition becomes true otherwise false. [ $a -lt 20 -a $b -gt 100 ] is false.

Department of Information Technology, VIIT, Pune-48


String Operators in BASH
Assume variable a holds "abc" and variable b holds "efg" then −
Operator Description Example
= Checks if the value of two operands are equal or not; if yes, then the [ $a = $b ] is not true.
condition becomes true.
!= Checks if the value of two operands are equal or not; if values are not equal [ $a != $b ] is true.
then the condition becomes true.
-z Checks if the given string operand size is zero; if it is zero length, then it [ -z $a ] is not true.
returns true.
-n Checks if the given string operand size is non-zero; if it is nonzero length, then [ -n $a ] is true.
it returns true.
str Checks if str is not the empty string; if it is empty, then it returns false. [ str $a ] is not false.

Department of Information Technology, VIIT, Pune-48


Sample Script
• #!/bin/bash
• echo -e "Hi, please type the word: \c "
• read word
• echo "The word you entered is: $word"
• echo -e "Can you please enter two words? "
• read word1 word2
• echo "Here is your input: \"$word1\" \"$word2\""
• echo -e "How do you feel about bash scripting? "
• # read command now stores a reply into the default build-in variable $REPLY
• read
• echo "You said $REPLY, I'm glad to hear that! "
• echo -e "What are your favorite colours ? "
• # -a makes read command to read into an array
• read -a colours
• echo "My favorite colours are also ${colours[0]}, ${colours[1]} and ${colours[2]}:-)"

Department of Information Technology, VIIT, Pune-48


Output of Sample Script

• Hi, please type the word: Linuxconfig.org


• The word you entered is: Linuxconfig.org
• Can you please enter two words?
• Debian Linux
• Here is your input: "Debian" "Linux"
• How do you feel about bash scripting?
• good
• You said good, I'm glad to hear that!
• What are your favorite colours ?
• blue green black
• My favorite colours are also blue, green and black:-)

Department of Information Technology, VIIT, Pune-48


Conditional statements (if/else)
• There are several ways to evaluate conditions, including if, if-else, if-elif-else, and nested
conditionals.

• if [[ condition ]];
• then
• statement
• elif [[ condition ]]; then
• statement
• else
• do this by default
• fi
• We can use logical operators such as AND -a and OR -o to make comparisons
• if [ $a -gt 60 -a $b -lt 100 ] // This statement checks if both conditions are true:
• a is greater than 60 AND b is less than 100.

Department of Information Technology, VIIT, Pune-48


Conditional statements (if/else)

• Let's see an example of a Bash script that uses if, if-else, and if-elif-else statements to
determine if a user-inputted number is positive, negative, or zero:
• #!/bin/bash
• echo "Please enter a number: "
• read num
• if [ $num -gt 0 ]; then
• echo "$num is positive"
• elif [ $num -lt 0 ]; then
• echo "$num is negative"
• else
• echo "$num is zero"
• fi

Department of Information Technology, VIIT, Pune-48


Conditional statements (if/else)
• Looping and Branching in Bash
• While loop
• While loops check for a condition and loop until the condition remains true. We need to
provide a counter statement that increments the counter to control loop execution.
• In the example below, (( i += 1 )) is the counter statement that increments the value of i.
The loop will run exactly 10 times.

• #!/bin/bash
• i=1
• while [[ $i -lt 10 ]] ; do
• echo "$i"
• (( i += 1 ))
• done

Department of Information Technology, VIIT, Pune-48


Case statements
• In Bash, case statements are used to compare a given value against a list of patterns and
execute a block of code based on the first pattern that matches. The syntax for a case
statement in Bash is as follows:
• fruit="apple"
• case $fruit in
• "apple")
• echo "This is a red fruit."
• ;;
• "banana")
• echo "This is a yellow fruit."
• ;;
• "orange")
• echo "This is an orange fruit."
• ;;
• *)
• echo "Unknown fruit."
• ;;
• esac

Department of Information Technology, VIIT, Pune-48


End of Unit - I

Department of Information Technology, VIIT, Pune-48


Department of Information Technology, VIIT, Pune-48

You might also like