Unit 3 Cse111
Unit 3 Cse111
Unit 3 Cse111
L T P :2 0 0
1
www.lpu.in Lovely Professional University
UNIT - 3
Linux OS and its features
• Linux is one of the popular versions of the UNIX operating System.
• It is free to use.
2
www.lpu.in Lovely Professional University
Linux OS and its features
Components of Linux System
Linux Operating System has primarily three components
• Kernel − Kernel is the core part of Linux. It is responsible for all major
activities of this operating system. It consists of various modules and it
interacts directly with the underlying hardware. Kernel provides the
required abstraction to hide low level hardware details to system or
application programs.
• System Library − System libraries are special functions or programs using
which application programs or system utilities accesses Kernel's features.
These libraries implement most of the functionalities of the operating
system and do not requires kernel module's code access rights.
• System Utility − System Utility programs are responsible to do
specialized, individual level tasks.
3
www.lpu.in Lovely Professional University
• Kernel Mode vs User Mode
• Kernel component code executes in a special privileged mode called kernel
mode with full access to all resources of the computer. This code represents
a single process, executes in single address space and do not require any
context switch and hence is very efficient and fast. Kernel runs each
processes and provides system services to processes, provides protected
access to hardware to processes.
• Support code which is not required to run in kernel mode is in System
Library. User programs and other system programs works in User Mode
which has no access to system hardware and kernel code. User programs/
utilities use System libraries to access Kernel functions to get system's low
level tasks.
4
www.lpu.in Lovely Professional University
• Kernel Space
• Definition: Kernel space is the portion of memory reserved for the
operating system's kernel and its core functionalities. Only the kernel has
access to this memory area, and it runs with high privileges (also called
privileged mode or supervisor mode). All the critical parts of the OS—
such as device drivers, memory management, process scheduling, and
hardware control—operate here.
• Purpose: Kernel space allows the kernel to manage system resources,
directly control hardware, and provide a safe, controlled interface for
user space processes.
• Protection: Regular user applications are not allowed to access kernel
space directly. Any improper access to kernel space can lead to system
crashes or security vulnerabilities, so access is tightly controlled.
5
Example of Kernel Space:
System Calls: When a user program (running in user space)
needs to perform an action like reading a file, it invokes a
system call (e.g., read() or write()), which causes the OS to
switch into kernel mode. The kernel performs the requested
operation (like accessing a disk) in kernel space, then returns
the result to the user program.
Illustration:
Suppose a program wants to open a file. When it makes a
system call (open()), the control is passed from user space to
kernel space. The kernel then accesses the file system and
handles the hardware interaction needed to open the file.
6
• User Space
• Definition: User space is the memory area where all user applications
run. These include programs like text editors, web browsers, games, etc.
Applications running in user space have limited privileges and can only
access memory and resources in user space. They interact with the
system hardware through system calls, which are handled by the kernel.
• Purpose: User space is where most programs operate, safely isolated
from direct hardware control. This isolation ensures that even if a
program crashes or misbehaves, it doesn't affect the entire system.
• Protection: User space programs are restricted from accessing kernel
space directly, which prevents unauthorized or harmful interactions with
system hardware and resources.
7
example of User Space:
Regular Applications: Programs like Firefox, Gedit, or GIMP run
in user space. They can't directly interact with hardware like the
CPU or network devices. Instead, they must use system calls to
request actions from the kernel (e.g., reading files, allocating
memory).
Illustration:
When you open a web browser (a user space program) and load
a webpage, it needs to communicate over the network. The
browser sends a request for a network connection via a system
call to the kernel, which then communicates with the network
hardware on behalf of the browser. The browser itself doesn't
have direct access to network interfaces. 8
9
www.lpu.in Lovely Professional University
• Basic Features
• Portable − Portability means software can works on different types of
hardware in same way. Linux kernel and application programs supports
their installation on any kind of hardware platform.
• Open Source − Linux source code is freely available and it is community
based development project. Multiple teams work in collaboration to
enhance the capability of Linux operating system and it is continuously
evolving.
• Multi-User − Linux is a multiuser system means multiple users can access
system resources like memory/ ram/ application programs at same time.
• Multiprogramming − Linux is a multiprogramming system means
multiple applications can run at same time.
• Hierarchical File System − Linux provides a standard file structure in
which system files/ user files are arranged.
• Shell − Linux provides a special interpreter program which can be used to
execute commands of the operating system. It can be used to do various
types of operations, call application programs. etc.
• Security − Linux provides user security using authentication features like
password protection/ controlled access to specific files/ encryption of data.
10
www.lpu.in Lovely Professional University
Distribution versions
11
www.lpu.in Lovely Professional University
Installation
12
www.lpu.in Lovely Professional University
Linux Directory Structure and File System Hierarchy
Dir Description
13
www.lpu.in Lovely Professional University
14
www.lpu.in Lovely Professional University
Disk partitioning
Disk partitioning in Linux refers to the process
of dividing a storage device, such as a hard
drive or SSD, into separate, independent
sections called partitions. Each partition can be
used for different purposes, such as holding the
operating system, user files. Partitioning is
often done during the installation of Linux, but
it can also be done after installation.
15
Common Types of Partitions in Linux
1. Primary Partition: You can have up to four
extended partition.
16
How to partition a disk in Linux
17
How to partition a disk in Linux
• List the partitions: Use parted -l to identify the storage device you
want to partition.
• Typically, the first hard disk (/dev/sda or /dev/vda) will contain the
operating system, so look for another disk to find the one you want
(e.g., /dev/sdb, /dev/sdc, /dev/vdb, /dev/vdc, etc.).
18
www.lpu.in Lovely Professional University
• 2. Open the storage device: Use parted to begin working with
the selected storage device. It is important to indicate the
specific device you want to use. If you just type parted with no
device name, it will randomly select a storage device to
modify.
• 3. Set the partition table: The mklabel and mktable
commands are used for the same purpose (making a partition
table on a storage device). Remember mklabel will not make a
partition, rather it will make a partition table.
19
www.lpu.in Lovely Professional University
• 4. Review the partition table: Show information about the
storage device.
20
www.lpu.in Lovely Professional University
Comparison of Windows and Linux OS
S.NO Linux Windows
1. Linux is a open source operating system. While windows are the not the open source operating system.
5. Linux is more efficient in comparison of windows. While windows are less efficient.
7. Linux provides more security than windows. While it provides less security than Linux.
8. Linux is widely used in hacking purpose based systems. While windows does not provide much efficiency in hacking.
There are 3 types of user account – There are 4 types of user account –
9.
(1) Regular , (2) Root , (3) Service account (1) Administrator , (2) Standard , (3) Child , (4) Guest
Linux file naming convention in case sensitive. Thus, sample and In Windows, you cannot have 2 files with the same name in
11.
SAMPLE are 2 different files in Linux/Unix operating system. the same folder.
21
www.lpu.in Lovely Professional University
Virtual Machines
• A Virtual Machine (VM) is a compute resource that uses software instead
of a physical computer to run programs and deploy apps. One or more
virtual “guest” machines run on a physical “host” machine. Each virtual
machine runs its own operating system and functions separately from the
other VMs, even when they are all running on the same host. This means
that, for example, a virtual MacOS virtual machine can run on a physical
PC.
• Virtual machine technology is used for many use cases across on-premises
and cloud environments. More recently, public cloud services are using
virtual machines to provide virtual application resources to multiple users
at once, for even more cost efficient and flexible compute.
22
www.lpu.in Lovely Professional University
A virtual machine (VM) is a software-based
emulation of a physical computer that runs an
operating system (OS) and applications just like
a real computer would. It allows multiple OS
environments to exist simultaneously on a
single physical machine, using the resources of
that machine, such as CPU, memory, and
storage, as if they were separate computers.
23
1. Host Machine: The physical computer on which the virtual machine
runs. It provides the hardware resources, such as CPU, RAM, and disk
space.
2. Guest Machine: The virtual machine running inside the host. It behaves
like a complete, independent computer, including its own operating
system and software.
3. Hypervisor (Virtual Machine Monitor): The software layer that enables
the creation and management of virtual machines. It allows multiple
guest operating systems to share the hardware resources of the host
system. There are two types:
i. Type 1 (Bare Metal): Runs directly on the hardware (e.g., VMware
ESXi, Microsoft Hyper-V, KVM).
ii. Type 2 (Hosted): Runs on top of an existing operating system (e.g.,
VMware Workstation, VirtualBox).
4. Virtualization: The process of creating a virtual version of something, in
this case, a computer, including the hardware, OS, and applications.
24
• The hypervisor allocates the host machine's
resources (like CPU cycles, memory, and storage) to
each virtual machine.
• Each guest operating system is installed inside the
VM as though it were being installed on a physical
computer.
25
• What are virtual machines used for?
• Virtual machines (VMs) allow a business to run an operating system that
behaves like a completely separate computer in an app window on a
desktop.
• VMs may be deployed to accommodate different levels of processing
power needs, to run software that requires a different operating system, or
to test applications in a safe, sandboxed environment.
• Virtual machines have historically been used for server virtualization,
which enables IT teams to consolidate their computing resources and
improve efficiency.
26
www.lpu.in Lovely Professional University
• What are virtual machines used for?
Additionally, virtual machines can perform specific tasks considered too risky
to carry out in a host environment, such as accessing virus-infected data or
testing operating systems. Since the virtual machine is separated from the rest
of the system, the software inside the virtual machine cannot tamper with the
host computer.
27
www.lpu.in Lovely Professional University
Kernel and types of kernels
• A Kernel is an intermediary between applications and hardware.
• Functions of a Kernel
A Kernel in an operating system performs the following functions:
• Device Management: Processes require various peripheral devices such as
a mouse and keyboard connected to the computer to perform various tasks.
The Kernel manages the allocation of the peripheral devices.
• Resource Management: Kernel shares the resources between different
processes while ensuring that every process has uniform access to the
resources.
• Memory Management: Every process requires some memory to execute.
The Kernel allows the processes to access the memory safely.
• Access Computer Resource: A kernel can access different computer
resources such as RAM, CPU, I/O devices, and other resources. The Kernel
decides which memory each process will use, and the action is taken if
memory is unavailable.
28
www.lpu.in Lovely Professional University
More about Linux Kernel
29
www.lpu.in Lovely Professional University
More about Linux Kernel
30
www.lpu.in Lovely Professional University
Basic types of kernels
• 3 basic types of kernels as below:
• Monolithic
• Microkernel
• Hybrid
31
www.lpu.in Lovely Professional University
1. Monolithic Kernel
Description: A monolithic kernel is a single,
large program where all the operating system's
services, such as process management,
memory management, file system, device
drivers, and system calls, are included in one
large codebase.
32
• Advantages:
• Fast and efficient due to minimal communication
overhead between components.
• Direct access to system hardware, which can lead to high
performance.
• Disadvantages:
• Difficult to maintain and debug because all components
are tightly integrated.
• Any bug in one part of the kernel can potentially crash the
entire system.
• Examples:
• Linux kernel
• Unix (original versions)
33
Microkernel
Description: A microkernel is a smaller, more
modular kernel that only includes essential
services such as CPU scheduling, memory
management, and inter-process
communication. Other services like device
drivers, file systems, and network protocols run
in user space, outside the kernel.
34
Advantages:
• Improved stability and security since most OS
services run in user space; a failure in one service
doesn't crash the entire system.
• Easier to maintain and extend because components
are modular.
Disadvantages:
• Communication between user space and kernel
space can introduce overhead, potentially reducing
performance.
35
Hybrid Kernel
Description: A hybrid kernel is a combination of
monolithic and microkernel architectures. It
aims to combine the performance of a
monolithic kernel with the modularity and
security of a microkernel. Core services run in
kernel space, but some drivers and system
services may run in user space.
36
Advantages:
• Balanced approach, with a good mix of performance and
stability.
• Easier to manage and extend than a pure monolithic kernel.
Disadvantages:
• Still larger and more complex than a microkernel.
37
Exokernel
Description: An exokernel is a highly specialized
and minimal kernel that gives user-level
applications more direct access to hardware
resources. Instead of abstracting hardware (as
other kernels do), it allows applications to
manage resources like memory and CPU
themselves.
38
Advantages:
• Offers high performance and flexibility, as
applications can directly control hardware
resources.
• Very lightweight and efficient since it avoids
abstractions.
Disadvantages:
• More complex application development because
the OS doesn’t provide the usual abstractions.
39
Basic types of kernels
40
www.lpu.in Lovely Professional University
Other Shell Commands:
• ls • rmdir
• cat • mkdir
• man • rm
• cd • chmod
• touch • pwd
• cp • ps
• mv • kill
41
ls command
• The ls command is used to list files or directories in Linux and other Unix-
based operating systems.
• Use of ls command as below:
42
www.lpu.in Lovely Professional University
cat command
• Outputs the contents of a text file.
• You can use it to read brief files or to concatenate files together.
• To append file1 onto the end of file2, enter:
• cat file1 >> file2
• To view the contents of a file named myfile, enter:
• cat myfile
43
www.lpu.in Lovely Professional University
man command
• The man command is a built-in manual for using Linux commands.
• Displays the user manual of any command that we can run on the terminal.
It provides a detailed view of the command which includes NAME,
SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN
VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS.
• Basic Symbol
45
www.lpu.in Lovely Professional University
Touch
The touch command's
primary function is to
modify a timestamp.
46
cp
• This command copies a file, preserving the original and creating an
identical copy.
– cp -i oldfile newfile
mv
mv stands for move.
mv is used to move one or more files or directories from one place to
another in a file system like UNIX.
Use it as:
mv [Option] source destination
47
www.lpu.in Lovely Professional University
Mkdir
• The mkdir command is used to create (or make) a directory.
• Example:
• # mkdir LPUCSE
rmdir
• The rmdir directory is used to remove directories, but only those that are
empty (i.e., contain no files or subdirectories). In order to delete a directory
with actual contents, you must use the rm -R command.
• Example
• To remove an empty directory:
• # rmdir /mike
48
www.lpu.in Lovely Professional University
Rm
Use the rm command to remove files you no longer need.
Example
Removing one file at a time
$ rm CSEA.txt
Pwd
Simply type pwd into your terminal, and the command will output the absolute
path of your print working directory.
The pwd command writes to standard output the full path name of your current
directory (from the root directory). All directories are separated by a /
(slash). The root directory is represented by the first /, and the last directory
named is your current directory.
The ps command, short for Process Status, is a command line utility that is
used to display or view information related to the processes running in a
Linux system.
49
www.lpu.in Lovely Professional University
ps
The ps command, short for Process Status, is a command line utility that is
used to display or view information related to the processes running in a
Linux system.
kill
kill command in Linux (located in /bin/kill), is a built-in command which is
used to terminate processes manually.
50
www.lpu.in Lovely Professional University
• Activity
51
www.lpu.in Lovely Professional University
ACTIVITY
1. Create two directories.
2. Create two files in both directories(dir1 and dir2).
3. In first directory, write something in first file(file1.txt) and copy it to
second file(file2.txt).
4. Then create a third file(file3.txt) in the current directory and write
something to it, then append file1 and file3.
5. Create a subdirectory and move file2 to that subdirectory.
6. Move file3 to another directory(dir2) and copy the contents of file3 in any
of the file of that directory.
7. Delete file3.
8. Display the contents of both file in current directory(dir2).
9. Empty the dir2 and then delete it.
10. Delete dir1 along with its contents.
52
What does the pwd command do in Linux?
A) Prints the working directory
B) Changes the directory
C) Displays the contents of a file
D) Deletes a directory
53
Which command would you use to remove a
file named file.txt?
A) delete file.txt
B) rm file.txt
C) remove file.txt
D) unlink file.txt
54
Which command displays the contents of a file
in the terminal?
A) cat
B) show
C) view
D) list
55
What is the primary function of the grep
command?
A) Search for files
B) Search for text within files
C) Copy files
D) Move files
56
Which of the following is a hypervisor type
that runs directly on the host's hardware?
A) Type 1 hypervisor
B) Type 2 hypervisor
C) Cloud hypervisor
D) Hybrid hypervisor
57
Which hypervisor runs on top of an existing
operating system?
A) Type 1 hypervisor
B) Hosted hypervisor
C) Bare-metal hypervisor
D) None of the above
58
What is the main purpose of a virtual
machine?
A) To increase storage capacity
B) To run multiple operating systems on a
single physical machine
C) To improve graphics performance
D) To connect to the internet
59
What is a monolithic kernel?
A) A kernel that runs in user space
B) A kernel that contains all the essential
services within one large block of code
C) A kernel that is modular and can load/unload
modules at runtime
D) A kernel that is optimized for real-time
operations
60
Which of the following is a characteristic of a
microkernel?
A) It contains all device drivers
B) It runs most of the services in user space
C) It has high performance due to its size
D) It is not suitable for real-time applications
61
Which type of kernel is generally considered to
be more efficient for high-performance
computing?
A) Monolithic kernel
B) Microkernel
C) Hybrid kernel
D) Modular kernel
62