Unit 1 Presentation
Unit 1 Presentation
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.
3. 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).
4. Users – (People, Machines, other computers, programs).
Hierarchical view of computer system
CPU – Central Processing Unit
This is the brain of your 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.
RAM – Random Access Memory
Power On Switch sends electricity to the BIOS will then look for a small sector at the very beginning of your
motherboard on a wire called the Voltage Good primary hard disk called MBR.
line. The MBR contains a list, or map, of all of the partitions on your
If the power supply is good, then the BIOS computer‘s hard disk (or disks).
(Basic Input/Output System) chip takes over. After the MBR is found the Bootstrap Loader follows basic instructions
In Real Mode, CPU is only capable of using for starting up the rest of the computer, including the operating system.
approximately 1 MB of memory built into the In Early Kernel Initialization stage, a smaller core of the Kernel is
motherboard. activated.
The BIOS will do a Power-On Self Test This core includes the device drivers needed to use computer‘s RAM
(POST) to make sure that all hardware are chips.
working.
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.
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.
Functions of Operating System
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.
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 made turn off
everything stored in RAM will be erased automatically.
• In addition to the physical RAM installed in your computer, most modern
operating systems allow your computer to use a virtual memory system. Virtual
memory allows your 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.
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.
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
devices 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.
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.
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
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
2. Graphical User Interface
• With a graphical user interface (GUI), you interact with menus
and visual images
History of Operating System
User
The shell used to be in the
kernel but now is a utility outside Utilities Shell
of it.
Easy to change/debug.
Kernel
Many of them (sh, bsh, csh,
ksh, tcsh, wsh, bash)
Possible to switch between Hardware
them (chsh)
Virtual Machine
•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.
What is Shell ?
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)
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.
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
BASH Shell scripting
• $ cat/etc/shells <Enter>
• /bin/sh
• /bin/dash
• /bin/bash
• /bin/rbash
gedit
1. clear
2. #! /bin/bash
3. echo “Hello world”
$ ./hello.sh //to execute the shell script
It will show the message “permission denied”
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.
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.
Basic Shell Commands
• 3). Extract, sort, and filter data Commands:
• grep : This command is used to search for the specified text in a
file.
• grep with Regular Expressions: Used to search for text using
specific regular expressions in file.
• sort : This command is used to sort the contents of files.
• wc : Used to count the number of characters, words in a file.
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.
• ln file1 file2: Creates a physical link.
• ln -s file1 file2: Creates a symbolic link.
• 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.
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.
Creating First bash script
It will show the message “permission denied”..
As bydefault user have no execute permission.
$ chmod +x hello.sh
$ ls –al
-rwx-rwx-rx
$ ./hello.sh <enter>
Hello world
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.
• 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.
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 "
NAME[1]=“lmn"
• NAME3=“xyz"
NAME[2]=“xyz"
• NAME4=“pqr" NAME[3]=“pqr"
• NAME5=“efg“ NAME[4]=“efg"
• We can use a single array to store all the above mentioned names.
• array_name[index]=value
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]}"
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
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
Gathering input
• 2. Reading from a file
• This code reads each line from a file named input.txt and prints it 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.
Displaying output
• 3. Appending to a file:
• echo "More text." >> output.txt
• This appends the text "More text." to the end of the file output.txt.
Basic Operators in BASH
• Arithmetic Operators
• Relational Operators
• Boolean Operators
• String Operators
• #!/bin/sh
• val=`expr 2 + 2`
• echo "Total value : $val“ output - Total value : 4
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 `expr $b % $a` will give 0
returns 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 [ $a == $b ] will return false.
true.
!= (Not Equality) Compares two numbers, if both are different then [ $a != $b ] will return true.
returns 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.
Relational Operators in BASH
Assume variable a holds 10 and variable b holds 20 then −
Oper Description Example
ator
-eq Checks if the value of two operands are equal or not; if yes, then the [ $a -eq $b ] is not true.
condition becomes true.
-ne Checks if the value of two operands are equal or not; if values are not
[ $a -ne $b ] is true.
equal, then the condition becomes true.
-gt Checks if the value of left operand is greater than the value of right operand;
[ $a -gt $b ] is not true.
if yes, then the condition becomes true.
-lt Checks if the value of left operand is less than the value of right operand; if
[ $a -lt $b ] is true.
yes, then the condition becomes true.
-ge Checks if the value of left operand is greater than or equal to the value of
[ $a -ge $b ] is not true.
right 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.
Boolean Operators in BASH
Assume variable a holds 10 and variable b holds 20 then −
• 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.
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
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
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