0% found this document useful (0 votes)
9 views44 pages

1.) Lecture-2 - Linux Architectureffygccgg

The document provides an overview of Linux system architecture, detailing components such as the kernel, system call interface, and user interfaces, as well as file, process, and memory management. It also discusses the differences between monolithic and micro kernels, their advantages and disadvantages, and outlines the Linux file system structure and access permissions. Additionally, it covers common Linux shell commands and file types, emphasizing the multiuser capabilities and file access control mechanisms in Linux.

Uploaded by

czaetvwp
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)
9 views44 pages

1.) Lecture-2 - Linux Architectureffygccgg

The document provides an overview of Linux system architecture, detailing components such as the kernel, system call interface, and user interfaces, as well as file, process, and memory management. It also discusses the differences between monolithic and micro kernels, their advantages and disadvantages, and outlines the Linux file system structure and access permissions. Additionally, it covers common Linux shell commands and file types, emphasizing the multiuser capabilities and file access control mechanisms in Linux.

Uploaded by

czaetvwp
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/ 44

Course Instructor: Debjani Ghosh

ARCHITECTURE OF LINUX
Linux System Architecture
Linux System Architecture

 Kernel
– The part of an OS where the real
work is done

 System call interface


– Comprise a set of functions (often
known as Application
Programmer’s Interface API) that
can be used by the applications
and library routines to use the
services provided by the kernel
 Application User’s Interface
– Interface between the kernel and
user
– Allow user to make commands to
the system
– Divided into text based and
graphical based
Linux System Architecture

 File Management
– Control the
creation, removal
of files and
provide directory
maintenance
– For a multiuser
system, every user
should have its own
right to access files
and directories
Linux System Architecture

 Process Management
– For a multitask system, multiple
programs can be executed
simultaneously in the system
– When a program starts to execute, it
becomes a process
– The same program executing at two
different times will become two different
processes
– Kernel manages processes in terms of
creating, suspending, and terminating
them
– A process is protected from
other processes and can
communicate with the
others
Linux System Architecture

 Memory management
– Memory in a computer is divided into main
memory (RAM) and secondary storage
(usually refer to hard disk)
– Memory is small in capacity but fast in
speed, and hard disk is vice versa
– Data that are not currently used should
be saved to hard disk first, while data
that are urgently needed should be
retrieved and stored in RAM
– The mechanism is referred as memory
management

 Device drivers
– Interfaces between the kernel and the
BIOS
– Different device has different driver
Kernel
 A core component of Operating System without
which OS can't work

 Kernel is the nervous system of OS

 It controls everything in OS including I/O


Management, Process Management and so on

 It is a bridge between applications and the actual


data processing done at the hardware level

 It acts as an interface between the user


applications and the hardware
Tasks of kernel
1. Central Processing Unit
• The Kernel takes responsibility for deciding at anytime which
of the many running programs should be allocated to the
processors

2. Random Access Memory


• It is used to store both program instructions and data.
• Often multiple programs will want access to memory,
frequently demanding more memory than the computer has
available.
• Responsible for deciding which memory each process can use
and determining what to do when not enough memory is
available.
Tasks of kernel(Continued..)
3. Input/output Devices
• The Kernel allocates requests from applications to perform I/O to
an appropriate device and provides convenient methods for using
the device
4. Memory Management
• The Kernel has full access to the system's memory and must allow
processes to safely access this memory as they require it
5.Device Management
• A Kernel must maintain a list of available devices.
• This list may be known in advance configured by the user or
detected by the operating system at run time (normally called plug
and play)
Tasks of kernel (Continued..)
• Scheduling of Process (Dispatching)
• Interprocess Communication
• Process Synchronization
• Context Switching
• Manipulation of Process Control Blocks
• Interrupt Handling
• Process Creation and Destruction
• Process Suspension and Resumption
Compare the below programs
def add(a, b):
# Define two numbers
return a + b
a = 10
b=5
def subtract(a, b):
return a - b
# Perform addition
addition = a + b
num1 = 10
num2 = 5
# Perform subtraction
subtraction = a - b
result_add = add(num1, num2)

# Print the results


result_sub = subtract(num1, num2)
print(f"Addition of {a} and {b} is:
{addition}")
print(f"Addition of {num1} and {num2} is:
{result_add}")
print(f"Subtraction of {a} and {b} is:
{subtraction}")
print(f"Subtraction of {num1} and {num2}
is: {result_sub}")
Types of Kernel
Monolithic Kernel
• Run in Kernel space every basic system services like
• process and memory management,
• interrupt handling and I/O Communication,
• file system etc in Kernel space

• Used by Unix, Linux like Operating systems

• Since there is less software involved, it is faster


• Every component of the Operating system is contained in the kernel and can
directly communicate with each other simply by using function calls.
• The Kernel typically executes with unrestricted access to the computer system

• This approach provides rich and powerful hardware access


Monolithic Kernel
Pros of Monolithic Kernel
• Smaller in source and compiled forms
• Less code generally means fewer bugs and security problems is
also less
• System calls are used to do operations in monolithic kernel
• Execution is fast
• It has all the things in kernel itself so we don't need any extra
mechanism for handling of I/O and process at the time of
application making
Cons of Monolithic Kernel
• Coding in kernel space is hard, since you cannot use common
libraries
• Debugging is harder, rebooting the computer is often needed
• Bugs in one part of kernel produce strong side effects
• Kernels often become very huge and difficult to maintain
• Not portable one. Monolithic kernels must be rewritten for each
new architecture that the OS is to be used on.
Micro Kernel
• The kernel provides basic functionality that allows the execution of
servers and separate programs
• The Kernel is broken into separate processes known as server
• Some of the servers run in user space and some in kernel space
• All servers are kept separate and run in different address spaces
• The communication in microkernels is done via message passing
• The servers communicate through Interprocess
Communication(IPC)
• Servers invoke "services" from each other by sending messages
• It is also possible to dynamically switch among operating systems
and to have more than one active simultaneously
Micro Kernel
Advantages of Micro Kernel
• Easier to maintain than Monolithic Kernel
• Crash resistant (If one server fails, other servers can still work
efficiently)
• Portable
• Smaller in size
• Contains smaller amount of code. It increases stability and
security.
Key Comparisons
Basis for Comparison Micro Kernel Monolithic Kernel

Size Smaller in size Larger than microkernel


Execution Slow Fast
Extendible Easy to extend Hard to extend
Security If a service crashes, it If a service crashes, the
does effects on working whole system crashes in
on the microkernel monolithic kernel
Code To write a microkernel To write a monolithic
more code is required kernel less code is
required
Example QNX, Symbian, Linux, BSDs(FreeBSD,
L4Linux etc. OpenBSD, NetBSD)etc.
Linux File System Structure
 According to the File System Standard (FSSTND)
proposed in 1994, every LINUX system should contain
a set of standard files and directories
Kernel
Linux File System Structure
 Root Directory ( / )
– Top of the file system. Similar to \ in DOS
 /bin
– Contain the binary (executable code) of most essential
Kernel
Linux commands, e.g. bash, cat, cp, ln, ls, etc.
 /boot
– Contain all the files needed to boot the Linux system,
including the binary of the Linux kernel. E.g., on Red Hat
Linux 6.1, the kernel is in /boot/vmlinux-2.2.5-15 file
 /dev
– Contain the special files for devices, e.g. fd0, hd0, etc.
Linux File System Structure
 /etc
– Contain host-specific files and directories, e.g.
information about system configuration
– /etc/passwd
– This file contains login information of users in the
system
– For every user, one line of record is stored in the
following format:
login_name : dummy_or_encrypted_password : user_ID :
group_ID : user_info : home_directory : login_shell
Linux File System Structure
– E.g. rahul:x:134:105:MohanARahul:/home/rahul:/bin/bash
– rahul : login name
– x : means that it is a dummy password. The encrypted password is stored
in /etc/shadow. This field can also be used to store the actual encrypted
password. In any case, the original (unencrypted) password cannot be
seen by anyone, including the administrator
– 134 : a user id given to that user. Range from 0 to 65535.
• 0 is assigned to super-user. 1 to 99 are reserved
– 105 : a group id given to that user to indicate which group he belongs
to. Range from 0 to 65535. 0 to 99 reserved
– Mohan A Rahul : user info, usually user’s full name
– /home/rahul : home directory of the user
– /bin/bash : the location of the shell the user is using
Linux File System Structure
 /home
– Contain the home directories of every user in the
system, e.g. dlun, guest, etc
 /lib
– Store all essential libraries for different language
compilers
 /lost+found
– Contain all the files on the system not connected to any
directory.
– System administrator should determine the fate of the
files in this directory
Linux File System Structure
 /mnt
– Use by system administrator to mount file systems
temporarily by using the mount command
– Before using any devices, they have to be mounted to the
system for registration
– For example, after mounting a CD-ROM, the file system
in it will be mapped to /mnt/cdrom directory
– User can then read and write files in the CD-ROM by
accessing this directory
– Similar to mapping a drive letter to a CD-ROM in
Windows
– Different from the special file in /dev. Special file is only
a place where data of the CD-ROM is transferred or
stored. No file system concept
Linux File System Structure
 /opt
– Use to install add-on software packages, e.g. star office,
etc.
 /proc
– Contain process and system information
 /root
– Home directory of the user root, usually the
administrator
 /sbin
– The directories /sbin, /usr/sbin, and /usr/local/sbin
contain system administration tools, utilities and
general root only commands, such as halt, reboot and
shutdown
Linux File System Structure
 /tmp
– Contain temporary files. Usually files in this directory will
be deleted from time to time to avoid the system fills with
temp files
 /usr
– One of the largest sections of the Linux file system
– Contain read-only data that are shared between various
users, e.g. the manual pages needed for the command man.
Stored in /usr/man direcrtory
 /var
– Contain data that keeps on changing as the system is
running. E.g. /var/spool/mail directory keeps the mail of
user
Linux Shell
• Shell interprets the command whoami pwd
ls Bash, Tcsh, Zsh
and request service from kernel
• Similar to DOS but DOS has only
one set of interface while Linux Kernel
can select different shell
• –Bourne Again shell (Bash),
TC shell (Tcsh), Z shell
(Zsh)
 Different shell has similar but different functionality
 Bash is the default for Linux
 Graphical user interface of Linux is in fact an application
program work on the shell
Example Linux Shell
Commands
 Frequently used commands available in most shells:
– ls : to show (list) the names of the file in the current
directory
– cd : change directory,

– e.g. cd / change to the root directory


cd .. change to the parent of that directory
– cp : copy one file to another
– e.g. cpabc.txt xyz.txt copy abc.txt to xyz.txt
– rm : remove a file
Example Linux Shell
Commands
– man : ask for the manual (or help) of a command
– e.g. man cd Kernel
ask for the manual of the command cd
– pwd : show the name of the present working directory
– cat : to show the content of a text file
– e.g. cat abc.txt show the content of abc.txt
– whoami : to show the username of the current user

More Linux/Unix commands


File Management
• In Linux, file is defined as simply the thing that deals with a
sequence of bytes
 Hence everything are files
– An ordinary file is a file; a directory is alsoKernel
file; a network
card, a hard disk, any device are also files since they deal
with a sequence of bytes
 Linux supports five types of files
– simple/ordinary file (text file, c++ file, etc)
– directory
– symbolic (soft) link
– special file (device)
– named pipe (FIFO)
Example Linux File

Kernel

Names in blue are directories, indicated by a


letter d at the beginning of the line
Linux File
 Symbolic (soft) link
– Not a real file, just a link to another file
– Allow giving another name to a file without actually
duplicates it – hence save memory space
Kernel
 Special file (device)
– Each hardware device, e.g. keyboard, hard disk, CD-
ROM, etc is associated with at least one file
– Usually store in /dev directory
– Applications can read and write any devices by reading
and writing their associate file – hence the access
method is known as device independent
– Divide into two types: character special files, e.g.
keyboard, and block special files, e.g. disk
Linux File

Kernel
Linux File

Kernel
Linux File Access Privilege
 Linux is a multiuser system, the files of all users are
stored in a single file structure
 Mechanism is required to restrict one user to access the files
of another user, if he is not supposed to
 User can impose access permission to each file to restrict its
access
 The term “access permission” refers to
– read permission
– write permission
– execute permission
Linux File Access Privilege
Linux File Access Privilege
Linux File Access Privilege
 Access permission can also be assigned to a directory
 Directory is also a file that contains the attributes of the files
inside it
 If read permission is not given to a directory
– cannot show the structure of this directory
– e.g. cannot use ls
 If write permission is not given to a directory
– cannot modify anything of the directory structure
– e.g. cannot copy a file into this directory since it will
modify the directory structure by adding one more file
 If execute permission is not given to a directory
 nearly nothing can be done with this directory, even cd
Linux File Access Privilege
 The access permission of a file or directory can be changed by
using the command

• chmod xyz filename/directory name

 xyz refers 3 digit in octal form


Linux File Access Privilege

You might also like