Unit 3 Cse111

Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

Orientation to Computing-I

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 open source as its source code is freely available.

• It is free to use.

• Linux was designed considering UNIX compatibility.

• Its functionality list is quite similar to that of UNIX.

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

1. Insert a bootable Linux USB drive


2. Click the start menu
3. Then hold down the SHIFT key while clicking Restart
4. Then select Use a Device
5. Find your device in the list
6. Your computer will now boot Linux
7. Select Install Linux
8. Go through the installation process

12
www.lpu.in Lovely Professional University
Linux Directory Structure and File System Hierarchy
Dir Description

The directory called "root." It is the


starting point for the file system
/
hierarchy. Note that this is not related
to the root, or superuser, account.

Binaries and other executable


/bin
programs.
/etc System configuration files.
/home Home directories.
/opt Optional or third party software.
Temporary space, typically cleared on
/tmp
reboot.
/usr User related programs.
/var Variable data, most notably log files.

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

primary partitions on a disk.


2. Extended Partition: If you need more than

four partitions, one of the primary partitions


can be designated as an extended partition,
which can hold multiple logical partitions.
3. Logical Partition: Partitions inside an

extended partition.
16
How to partition a disk in Linux

• Creating and deleting partitions in Linux is a regular practice


because storage devices (such as hard drives and USB drives) must
be structured in some way before they can be used.

• In most cases, large storage devices are divided into separate


sections called partitions. Partitioning also allows you to divide your
hard drive into isolated sections, where each section behaves as its
own hard drive.

17
How to partition a disk in Linux

The following explains the process of partitioning a storage device


with the parted command.

• 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.

• 5. Get help: To find out how to make a new partition, type:


(parted) help mkpart.

• 6. Make a partition: To make a new partition (in this


example, 1,396MB on partition 0), type the following:
(parted) mkpart primary 0 1396MB

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.

2. Linux is free of cost. While it is costly.

3. It’s file name case-sensitive. While it’s file name is case-insensitive.

4. In Linux, monolithic kernel is used. While in this, micro kernel is used.

5. Linux is more efficient in comparison of windows. While windows are less efficient.

While there is back slash is used for Separating the


6. There is forward slash is used for Separating the directories.
directories.

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

Administrator user has all administrative privileges of


10. Root user is the super user and has all administrative privileges.
computers.

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.

• How do virtual machines work?


• The virtual machine runs as a process in an application window, similar to
any other application, on the operating system of the physical machine.

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

• A monolithic kernel is a type of kernel in which the complete OS runs in


the kernel space.
• A microkernel is a kernel type that implements an operating system by
providing methods, including low-level address space management, IPC,
and thread management.
• A hybrid kernel is an operating system kernel architecture that attempts to
combine aspects and benefits of microkernel and monolithic kernel
architectures used in computer operating systems.

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.

Examples: Windows NT (used in modern Windows OS)


Apple's XNU kernel (used in macOS and iOS)

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

• option – the search result output.


• section number – the section in which to look for the man page.
• command name – the name of the command which man page you want to
see.
44
www.lpu.in Lovely Professional University
cd command
• It changes your current directory location.
• By default, your Unix login session begins in your home directory.
• To switch to a subdirectory (of the current directory) named myfiles, enter:
• cd myfiles
• To switch to a directory named /home/dvader/empire_docs, enter:
• cd /home/dvader/empire_docs

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

• Execute various commands on Linux Operating System

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

You might also like