Unit1: Introduction To Linux Operating System

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 64

UNIT1

INTRODUCTION TO LINUX
OPERATING SYSTEM
Introduction and types of OS
• An Operating System (OS) is a software that
acts as an interface between computer
hardware components and the user.
• Every computer system must have at least one
operating system to run other programs.
• Applications like Browsers, MS Office, Notepad
Games, etc., need some environment to run
and perform its tasks.
Types of OS
Types of Operating System (OS)
• Single user
• Multiuser
• Batch Operating System
• Multitasking/Time Sharing OS
• Real Time OS
• Distributed OS
• Network OS
• Mobile OS
Linux operating system
• Linux, computer operating system develped in
the early 1990s by Finnish software engineer
Linus Torvalds.
• On October 5, 1991, Linus announced the first
“official” version of Linux, version 0.02.
• Linux distributions can be broadly categorized
into two groups:
First is commercial distros, and the second
includes the noncommercial distros,or spins.
Linux Operating System
• Examples of commercial flavors of Linux-based
distros are RHEL, SuSE Linux Enterprise (SLE),
etc.
• The noncommercial distros, on the other
hand, are free and open source.
• Examples of noncommercial flavors of Linux-
based distros are Fedora,OpenSuSE, Ubuntu,
goBuntu, Debian, etc.
Linux Operating System
• Linux is one of popular version of UNIX operating
System.
• It is open source and free.
• Linux can run on any x86 or x64 based PC.
• Ubuntu, federo,Redhat linux are some of the linux
distributions.
• Every Linux distribution comes with basic
applications like text editor, media player, office
applications and games like soltaire, chess etc.
Who uses Linux
• Linux can be used in super computers, smart
phones, servers,PC etc.
• Android is the most popular mobile O.S which
is based on linux kernel.
• The main use of Linux in all these is
maintenance cost is less.
Features
• Portable
• Opensource
• Multiuser
• Multiprogramming
• Shell
• Hierarchical File system
• Security
Architecture of Linux
Architecture of Linux
The architecture of a Linux System consists of
the following layers :
• Hardware Layer
• Kernel
• Shell
• Utilities
Shell interface
• Shell is a program which provides the interface
between the user and an operating system.
• The shell accepts and interprets commands and
forwards them to the kernel.
• Users cant interface with the OS without the shell.
• We can access a shell through a program called
Terminal.
• There are number of shells developed for UNIX like
systems each with different commands, syntax and
functions.
• In Unix, there are two major types of shells −
Bourne shell − If you are using a Bourne-type shell, the $ character is the
default prompt.
C shell − If you are using a C-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)
• The different C-type shells follow −
C shell (csh)
TENEX/TOPS C shell (tcsh)
Linux System calls
•  A system call is a request made by a program
to the operating system.
• It is a way in which the user request a service
from the kernel of OS.
• System calls are the only entry points into the
kernel system. All programs needing resources
must use system calls.
Linux System calls
• Types of System Calls : There are 5 different
categories of system calls –
– Process control: end, abort, create, terminate,
allocate and free memory.
– File management: create, open, close, delete,
read file etc.
– Device management
– Information maintenance
– Communication
Linux System Calls
System Call Services
• Process Control • fork()
exit()
wait()
exec()
• File Manipulation • open()
read()
write()
close()
• Device Manipulation • ioctl()
read()
write()
Linux System Calls
• Information • getpid()
Maintenance alarm()
sleep()
• Communication • pipe()
shmget()
mmap()
• chmod()
• Protection
umask()
chown()
Shared memory management
• Shared memory is a memory shared between
two or more processes. 
• It is an extra piece of memory that is attached
to some address spaces.
• Shared memory is a feature supported by
UNIX system V,including Linux,SunOS,Solarsis.
• The following figure shows two processes and
their address spaces.
Shared Memory Management

Process 1 Process2

Shared Memory

• Here the Shared memory is attached to both


address spaces and both procee1 and
process2 have access to shared memory.
Shared Memory Management
• Before using the shared memory what needs to be
done with the system calls, let us see this −
• Create the shared memory segment or use an already
created shared memory segment (shmget())
• Attach the process to the already created shared
memory segment (shmat())
• Detach the process from the already attached shared
memory segment (shmdt())
• Control operations on the shared memory segment
(shmctl())
Shared Memory Management
• A shared memory segment is identified by a unique
integer, the shared memory ID.
• The shared memory itself is described by a structure
of type shmid_ds in header file sys/shm.h.
• To use this , files sys/types.h and sys/ipc.h must be
included. Therefore, the program should start with
the following lines:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
Shared Memory Management
• A general scheme of using shared memory is the
following:
• For a server, it should be started before any client.
The server should perform the following tasks:
– Ask for a shared memory with a memory key and
memorize the returned shared memory ID. This is
performed by system call shmget().
– Attach this shared memory to the server's address
space with system call shmat().
– Initialize the shared memory, if necessary.
– Do something and wait for all clients' completion.
– Detach the shared memory with system
call shmdt().
Shared Memory Management
• For the client part, the procedure is :
I. Ask for a shared memory with the same memory
key and memorize the returned shared memory
ID.
II. Attach this shared memory to the client's address
space.
III. Use the memory.
IV. Detach all shared memory segments, if necessary.
V. Exit.
Device and disk management
• Device files are also known as device special files.
• All Linux device files are located in the /dev directory,
which is an integral part of the root (/) filesystem
because these device files must be available to the
operating system during the boot process.
• Device drivers are uniquely identified by their major
numbers.
• A device driver may be controlling a number of
physical and virtual devices; the individual device is
accessed via the minor number
• Under Linux and UNIX each and every
hardware device treated as a file. A device file
allows to accesses hardware devices so that
end users do not need to get technical details
about hardware.
• There are two types of device files based upon
how data written to them and read from them
is processed by the operating system and
hardware:
• Character special files or Character devices
• Block special files or Block devices
• A Character device(‘c’) is one with which the
driver communicates by sending and receiving
single characters(1 byte).
• Examples: Virtual terminals, terminals and serial
modems etc
• A Block device(‘b’)is which the driver
communicates by sending and receiving entire
blocks of data.(1 block= 512 bytes to 32KB).
• Examples: Hard disk, DVD/CD ROM, and memory
regions etc
• ls -l /dev
crw--w---- 1 root tty 4, 0 Jan 17 09:19 tty0
brw-rw---- 1 root disk 1, 0 Jan 17 09:19 ram0
brw-rw---- 1 root disk 8, 0 Jan 17 09:19 sda
lrwxrwxrwx 1 root root 3 May 18 10:26 cdrom -> sr0
drwxr-xr-x 2 root root 4096 May 5 15:49 bin
• In Linux all devices are connected to personal
computer using electronic drivers.The drivers
used are IDE & SCSI.
• IDE is also called as PATA and SCSI is also called as
SATA.
• By using IDE & SCSI we are partitioning devices.
• IDE drives device names would be
• /dev/hda {primary master}
• /dev/hdb {primary slave}
• /dev/hdc{secondary master}
• /dev/hdd{secondary slave}
• Once a drive has been partitioned we can also
add numbers to drive partitions.
• Only four partitions can be done on IDE drives.
• /dev/hda1, /dev/hda2, /dev/hda3, /dev/hda4.
• If we are using SCSI drive then the partitions be
in the form of :/dev/sda ,/dev/sdb etc.
• Partitions are divided into three types.
• Primary partitions
• Logical partitions
• Extended partitions
Disk management
• Linux disk management includes several
important tasks such as adding or removing
storage devices, creating and deleting
partitions, mounting partitions on appropriate
directories.
• To view all disk partitions in linux use
#fdisk –l
fdisk stands for fixed disk or format disk which
is most commonly used command line based
disk manipulation utility for a linux system.
• To view all partitions of specific hard disk
• fdisk -l /dev/hda
• fdisk –l /dev/sda
• To Create new partitions first be in fdisk
command then press n
• fdisk /dev/hda
• Then press n
• To Create primary partition first be in fdisk
command then press p.
• To Create extended partition first be in fdisk
command then press e.
• To delete a partition in linux first be in fdisk
command mode then press ‘d’.
• Then enter partition number you want to
delete.
• Only root user can perform the manipulations
of disk management.
Swap space management
• Swap space is used when the amount of
physical memory or RAM is full.
• If the RAM is full the inactive pages in memory
are moved to swap space.
• The combined system of RAM and swap space
is called virtual memory.
• Swap space is the smallest part in the hard
disk drive.
• To mange the swap space ,the steps to be
followed are:
• To create a swap space.
To create a swap space administrator needs
three things
1. Create the partition
2. Set the type of partition as 82 linux swap.
3. Format a swap signature on the device.
• Assign the partition type.
• Format the device.
• To create a partition of desired size
fdisk /dev/hda
• To make swap command applies a swap
signature to the device
mkswap /dev/hda1
• To activate the formatted swap space
swapon /dev/hda1
File System and Directory Structure
• A Linux file system is a structured collection of
files on a disk drive or a partition.
• The Linux file system contains the following
sections:
• The root directory (/)
• A specific data storage format (EXT2,EXT3,
EXT4, BTRFS and so on)
• A partition or logical volume having a
particular file system.
• The Linux kernel supports various file systems,
but the most commonly used is the ext4 file
system.
• Linux file system evolution:
• MINIX File System
• The Minix file system supported the Minix
operating system. It was first introduced in 1987 by
Andrew S. Tanenbaum.
• The Minix operating system and its file system were
mostly used for educational coding purposes.
Filename lengths were restricted to 14 characters,
and partitions were limited to 64MB. At the time,
hard drives supported partitions up to 140MB.
• By 1992 Minix was mostly out of use due to lack of
performance and development of the ext file
system.
ext File System:
• The ext file system stands for “Extended File System”. It was the
first file system designed to support the Linux kernel.
• Virtual File System (VFS) was used for the ext file system. Its
primary purpose was to allow the Linux kernel to access the ext
file system. The ext file system restricted filename lengths to 255
characters and supported partitions up to 2GB.
• While it managed to solve issues that the Minix file system had, it
had one major flaw – timestamping. Unlike today where each
Linux file has three timestamps (access timestamp, modified
timestamp, and changed timestamp), the ext file system allowed
only one timestamp per file.
• In January 1993, the ext2 file system was introduced. In time, all
users switched from ext to ext2.
ext2 File System :
• Remi Card designed the ext2 file system and
released it in January 1993, less than a year after
introducing the ext file system.
• Data from files were kept in data blocks of the same
length. The ext2 file system supported the maximum
file size of 2TB. Filename lengths were not limited in
characters, but in bytes – 255 bytes. It did not
support journaling.
• While this file system was largely used, it still had two
major issues:
• File corruption
• Performance loss
Ext3 filesystem:
• Stephen Tweedie designed the ext3 file system . It launched
in November 2001 with Linux kernel 2.4.15. It is still in use
today.
• It supports a maximum file size of 2TiB and restricts
maximum filename length to 255 bytes, like the ext2 file
system. The improvement is reflected in journaling.
• The journaling system keeps a “journal” of all changes in the
data structure that are yet to be commited.
• In case of power loss or system crash, logs stored via the
journaling system return data in a manner of seconds,
reducing the risk of corruption or data loss.
• The system writes the data in the correct areas of the file
system when the log is updated.
• ext4 File System
• The ext4 file system is the default file system of the
current Linux kernel. It was introduced in October 2008
with Linux kernel 2.6.28.
• The ext4 file system supports the maximum file size of
16TiB and restricts maximum filename lengths to 255
bytes.
• Several other new features are introduced in ext4:
multiblock allocation, delayed allocation, journal
checksum. fast fsck, etc.
• In ext4, you also have the option of turning the
journaling feature “off”.
Linux Directory Structure
• The Directory Structure in Unix & Linux are a
unified Directory Structure where in all the
directories are unified under the "/" Root file
system.
• Irrespective of where the File System is
physically mounted all the directories are
arranged hierarchically under the Root file
system.
/ – Root
• Every single file and directory starts from the root
directory.
• Only root user has write privilege under this directory.
/bin
• It contains binary executables
• The bin directory contains several useful commands
that are of use to both the system administrator as
well as non-privileged users.
• It usually contains the shells like bash, csh, etc.... and
commonly used commands like cp, mv, rm, cat, ls.
• /sbin – System Binaries
• This directory contains important system
management and administration files, such as
fdisk, fsck, ifconfig, init, mkfs, shutdown, and
halt.
• The linux commands located under this
directory are used typically by system
administrator, for system maintenance
purpose.
• /etc – Configuration Files
• Contains configuration files required by all
programs.
• This also contains startup and shutdown shell
scripts used to start/stop individual programs.
• For example: /etc/resolv.conf, /etc/logrotate.conf
• /dev
• This directory contains special files that are used to
represent the various hardware devices installed in
the system
• EX: hda, hdb ...
• /home
• This directory contains subdirectories that
serve as home directories for each user
account on your Linux system.
• /lib – System Libraries
• Contains library files that supports the binaries
located under /bin and /sbin
• Your kernel modules are also stored in the
modules subdirectory of /lib.
• /usr – User Programs
• Home directories for all users to store their
personal files.
• For example: /home/cse
• /tmp – Temporary Files
• Directory that contains temporary files
created by system and users.
• Files under this directory are deleted when
system is rebooted.
• /sys
• This directory contains information about the
hardware in your system
• /mnt – Mount Directory
• Temporary mount directory where sys admins can
mount file systems.
• /media
• This directory is used by some Linux distributions
(such as SUSE Linux) to mount external devices,
including CD drives, DVD drives, and floppy drives.
• /boot
• This directory contains bootloader files, which
are required in booting the operating system.
• /proc-process information
• Contains information about system process.
• This filesystem contains information about
running process. For example: /proc/{pid}
directory contains information about the
process with that particular pid.
Types of users in Linux
There are three types of users in linux

 System users: They are the software/applications users


created automatically by the system e.g mail , MySQL , ftp

 Super user: The superuser/root user/system administrator


is only one.
His duties are to install software + create or delete users +
look after the system resources .
The prompt sign of super user is # in all shells
 Normal users: The normal users can me many ,the
powers of normal users are limited but normal user
has full powers in his home directory .
The prompt sign of normal users in $ in bourne shell
and % in c-shell
File permissions
File permissions
Giving file permissions to files and directories

Command -option argument description

chmod 777 myfile Will assign read, write and execute permissions to
all owner, group and others (rwxrwxrwx)
chown -R ali mydir It will change the ownership of the Directory mydir for
the user ali, -R option will change ownership of the
sub directories residing inside mydir as well.
chgrp -R usman mydir It will change the group ownership of the directory mydir
for the user usman, -R option will change group
ownership of the sub directories residing inside mydir
as well.
Multiprocessing in Linux
• A computers capability to process more than one task
simultaneously is called multiprocessing.
• A multiprocessor operating system is capable of
running many programs simultaneously.
• Main objective of using multiprocessor operating
system is to consume high computing power and
increase the execution speed of system. 
• There are mainly two types of multiprocessor systems.
These are −
Symmetric Multiprocessor System
Asymmetric Multiprocessor System
• Multiprocessing systems can be represented
as:
Word Web antivirus
Email
processor browser

Operating System

CPU1 CPU2
• Operating systems which can run multiple
applications/processes are example of
Multitasking. Eg.) Windows OS can run Word
Processor and play music in a media player
simultaneously.
• In symmetric multiprocessing, multiple processors
share a common memory and operating system.
• Symmetric multiprocessing is also known as tightly
coupled multiprocessing as all the CPU’s are
connected at the bus level and have access to a
shared memory.
• All the parallel processors in symmetric
multiprocessing have their private cache memory to
decrease system bus traffic and also reduce the data
access time.
• Symmetric multiprocessing is useful for time sharing
systems as these have multiple processes running in
parallel.
• Asymmetric Multiprocessing system is a
multiprocessor computer system where not all
of the multiple interconnected central
processing units (CPUs) are treated equally.
• In asymmetric multiprocessing, only a master
processor runs the tasks of the operating
system. 
• Asymmetric multiprocessor system contains a
master slave relationship.
Load sharing
• load sharing entails sending a portion of the
traffic to one server and another portion
elsewhere.
• The loads do not need to be equal, they just
need to be set up in a way that does not
overwhelm the entire system.
• It improves total network performance.
Multithreading
• "Multithreading is a conceptual programming paradigm
where a process is divided into a number of sub-
processes called as threads.
• A single application/process can do multiple operations
simultaneously is example of Multithreading. Eg.) Word
Processor can print text on editor while user typing and
same time spell check will happen.
• One thread listens to Keyboard events and write text on
editor and another thread runs the spell check algorithm.
• "Thread is the path followed while executing a program.
Each thread has its own program counter, stack and
register."
• A thread is a light weight process.
Capabilities of superuser
• root is the superuser on Linux system. root is the first user
created during the process of installing any Linux distro like
Ubuntu for example.
• Most administration tasks, such as adding users or
managing file systems require that you first log in as root
(UID=0) .
• The root account, also known as the superuser account, is
used to make system changes and can override user file
protection.
• root has unlimited powers, and can do anything on system
hence the term superuser is used.
•  The root user can do many things an ordinary user cannot,
such as installing new software, changing the ownership of
files, and managing other user accounts.

You might also like