0% found this document useful (0 votes)
5 views13 pages

Operating System Unit IV

The document provides an overview of the Linux operating system, detailing its evolution, architecture, and key components such as the kernel, shell, and file system structure. It also covers essential Linux commands, shell scripting, and process management, highlighting the differences between foreground and background processes. Additionally, it outlines the stages of a process in Linux, from creation to termination.
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)
5 views13 pages

Operating System Unit IV

The document provides an overview of the Linux operating system, detailing its evolution, architecture, and key components such as the kernel, shell, and file system structure. It also covers essential Linux commands, shell scripting, and process management, highlighting the differences between foreground and background processes. Additionally, it outlines the stages of a process in Linux, from creation to termination.
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/ 13

Operating System Unit IV

Introduction to Linux: Linux is a widely-used open-source operating system,


similar to Windows, Mac, and Android. It shares similarities with Unix, another
operating system known for its commercial use. Linux is a free and open-source
Unix-like operating system kernel, widely used in servers, workstations, and
embedded systems. It evolved from a personal project by Linus Torvalds in 1991.
The architecture of Linux consists of a kernel, shell, system libraries, and
hardware. The file system utilizes superblock, and mounting/unmounting
mechanisms. Essential commands are used for file management, navigation, and
system administration. The kernel manages system resources, and process
management ensures efficient resource allocation.

Evolution of Linux
 1991: Initial Release:
Linus Torvalds announced the Linux kernel, inspired by the Unix operating system.
 1992: GNU GPL Licensing:
The Linux kernel was relicensed under the GNU General Public License, making it
open-source.
 1993-1994: Community Growth and Development:
The developer community expanded, and version 1.0 of the kernel was released in
1994.
 1995-1998: Wider Adoption and Support:
Linux was ported to different hardware platforms, and major companies began
announcing their support,

 1998-2000: Rise of Linux Distributions:


Distributions like Slackware, Debian, Red Hat, and SUSE emerged, providing users
with a complete operating system experience
 2000s: GNOME and X.Org:
GNOME, a graphical environment, gained popularity as a free alternative to KDE, and
the X.Org Foundation was formed to accelerate the development of the X server for
Linux
 2000s-Present: Widespread Use and Continued Development:
Linux has become a dominant force in various sectors, including servers, embedded
systems (e.g., Android), and even supercomputers

Architecture of Linux operating system


Linux is an open-source UNIX-based operating system. The main
component of the Linux operating system is Linux kernel. It is developed to
provide low-cost or free operating system service to personal system users.

Components of Linux: The main components of Linux operating system


are: Application, Shell, Kernel, Hardware, Utilities

Linux operating system architecture

1. Kernel:
Kernel is the main core component if Linux, it controls the activity of other
hardware components. It visualizes the common hardware resources and provide
each process with necessary virtual resources. It makes the process to wait in the
ready queue and execute in consequently to avoid any kind of conflict.
Different of types of kernel:
 Monolithic Kernel: Monolithic kernel is a type of operating system kernel,
where all the concurrent processes are executed simultaneously in the
kernel itself. All the processes share same memory recourses.
 Micro kernel: In micro kernel user services and kernel services are executed
in separate address spaces. User services are kept in user address space
and kernel services are kept in kernel address space.
 Exokernel: Exo-kernel is designed to manage hardware resources at
application level. High level abstraction is used in this operating system to
offer hardware resources access to kernel.
 Hybrid kernel: It is the combination of both monolithic kernel and
microkernel. It has speed and design of monolithic kernel and modularity
and stability of microkernel.

2. System Library:
System libraries are some predefined functions by using which any application
programs or system utilities can access kernel's features. These libraries are the
foundation upon which any software can be built.
Some of the most common system libraries are:
 GNU C library: This is the C library that provides the most fundamental
system for the interface and execution of C programs. This provides may in-
built functions for the execution.
 libpthread (POSIX Threads): This library plays important role for
multithreading in Linux, it allows users for creating and managing multiple
threads.
 libdl (Dynamic Linker): This library is responsible for the loading and linking
file at the runtime.
 libm (Math Library): This library provides user with all kind of mathematical
function and their execution.
3. Shell:
Shell can be determined as the interface to the kernel, which hides the internal
execution of functions of kernel from the user. Users can just enter the commend
and using the kernel's function that specific task is performed accordingly.

Different types of shell:


1. Command Line shell: command-line shell is a text-based interface that allows
users to execute commands by typing them. The shell interprets and processes
these commands, then displays the output in the terminal. Examples include bash
and zsh.
2. Graphical User Interface:
Executes the process provided by user in graphical way and output is displayed in
the graphical window.

Linux shell

4. Hardware Layer:
Hardware layer of Linux is the lowest level of operating system track. It plays a
vital role in managing all the hardware components. It includes device drivers,
kernel functions, memory management, CPU control, and I/O operations. This
layer generalizes hard complexity, by providing an interface for software by
assuring proper functionality of all the components.

5. System utility:
System utilities are the commend line tools that preforms various tasks provided
by user to make system management and administration better. These utilities
enable user to perform different tasks, such as file management, system
monitoring, network configuration, user management etc.

Linux File System Structure


A file system mainly consists of 3 layers.

1. Logical File System:


The Logical File System acts as the interface between the user applications and
the file system itself. It facilitates essential operations such as opening, reading,
and closing files. Essentially, it serves as the user-friendly front-end, ensuring that
applications can interact with the file system in a way that aligns with user
expectations.

2. Virtual File System:


A Virtual File System (VFS) is like a middleman between different types of file
systems on your computer, allowing them to work together seamlessly, even if
they are very different from each other. It hides the technical details of each file
system so that programs can access them in a consistent way

3. Physical File System:


The Physical File System is responsible for the tangible management and storage
of physical memory blocks on the disk. It handles the low-level details of storing
and retrieving data, interacting directly with the hardware components.
 Inode: Each file and directory in a Linux file system has an inode,
which stores metadata like permissions, ownership, size, and
pointers to the data blocks where the file's contents are stored.
 Super Block: The superblock contains fundamental information
about the file system, such as the total number of blocks, free
blocks, and root inode. It resides on the disk and also in memory,
providing a basis for interacting with the on-disk file system.
 Mounting: The mount command associates a file system (e.g., a
partition on a hard drive or a network share) with a directory in the
file system. This makes the file system's contents accessible through
that directory.
 Unmounting: The umount command detaches a mounted file
system from the directory it was mounted on. This makes the file
system's contents inaccessible through that directory. Unmounting
removes the VFS superblock and associated structures.

Linux Commands
1. Directory Navigation:
 ls: Lists files and directories in the current directory.
 cd: Changes the current working directory.
 pwd: Prints the current working directory.
 mkdir: Creates a new directory.
 rmdir: Removes an empty directory.

2. File Management:
 cp: Copies files or directories.
 mv: Moves or renames files or directories.
 rm: Removes files or directories.
 touch: Creates an empty file or updates the last modified time of an
existing file.
 cat: Displays the contents of a file.
 echo: Prints text to the terminal.
 less: Displays file contents interactively, page by page.

3. System and Process Management:


 grep: Searches for patterns in text.
 sudo: Executes commands with super user privileges.
 man: Displays the manual pages for a command.
 ps: Lists running processes.
 top: Displays a dynamic view of system processes.
 kill: Sends a signal to a process to stop it.
 df: Displays disk space usage.
 du: Estimates the disk space usage of files and directories.
 uname: Prints system information.
 whoami: Displays the current username.
 history: Displays a list of previously executed commands.

4. Networking:
 ping: Tests connectivity to a remote host.
 traceroute: Traces the route packets take to a remote host.
 ssh: Securely connects to a remote server.
 scp: Securely copies files between systems.
 wget: Downloads files from the web.
 curl: Transfers data using various protocols.

5. Archiving and Compression:


 tar: Creates archives of files and directories.
 gzip: Compresses files.
 gunzip: Decompresses files.
 zip: Creates zip archives.
 unzip: Extracts files from zip archives.

6. Permissions and Ownership:


 chmod: Changes file access permissions.
 chown: Changes file ownership.
 chgrp: Changes group ownership

Shell Scripting
Usually, shells are interactive, which means they accept commands as
input from users and execute them. However, sometimes we want to
execute a bunch of commands routinely, so we have to type in all
commands each time in the terminal.

As a shell can also take commands as input from file, we can write
these commands in a file and can execute them in shell to avoid this
repetitive work. These files are called Shell Scripts or Shell Programs.
Shell scripts are similar to the batch file in MS-DOS. Each shell script is
saved with `.sh` file extension e.g., myscript.sh.
A shell script has syntax just like any other programming language.
A shell script comprises the following elements –
 Shell Keywords - if, else, break etc.
 Shell commands - cd, ls, echo, pwd, touch etc.
 Functions
 Control flow - if..then..else, case and shell loops etc.

Why do we need shell scripts?


There are many reasons to write shell scripts:
 To avoid repetitive work and automation
 System admins use shell scripting for routine backups.
 System monitoring
 Adding new functionality to the shell etc.

Some Advantages of shell scripts


 The command and syntax are exactly the same as those directly
entered in the command line, so programmers do not need to
switch to entirely different syntax
 Writing shell scripts are much quicker
 Quick start
 Interactive debugging etc.

Some Disadvantages of shell scripts


 Prone to costly errors, a single mistake can change the command
which might be harmful.
 Slow execution speed
 Design flaws within the language syntax or implementation
 Not well suited for large and complex task
 Provide minimal data structure unlike other scripting languages.
etc.
Simple demo of shell scripting using Bash Shell
If you work on a terminal, something you traverse deep down in
directories. Then for coming few directories up in path we have to
execute a command like this as shown below to get to the “python”
directory:

In shell scripting, commands are classified as internal or external based


on how they are executed. Internal commands are built into the shell
itself, while external commands are separate programs that reside in
the file system. Internal commands are faster because they don't
require loading from disk, while external commands are more common
and often come pre-installed.
Internal Commands:
1. Definition: Routines directly part of the shell interpreter, not
requiring a separate external file to run.
2. Execution: Executed directly by the shell, without needing to launch
a new process.
3. Speed: Generally faster than external commands due to not needing
to load from disk.
4. Examples: cd, echo, pwd, help.

External Commands:
1. Definition: Standalone programs stored as executable files on the
file system.
2. Execution: The shell needs to locate the executable file (often
through the PATH variable) and then launch it.
3. Speed: Slower than internal commands due to the overhead of
loading and launching.
4. Examples: ls, cat, grep, df

Process Management in Linux


A process means program in execution. It generally takes an input,
processes it and gives us the appropriate output.
There are basically 2 types of processes.
1. Foreground processes: Such kind of processes are also known
as interactive processes. These are the processes which are to be
executed or initiated by the user or the programmer, they cannot
be initialized by system services. Such processes take input from the
user and return the output. While these processes are running we
cannot directly initiate a new process from the same terminal.
 The shell allows the user to start, stop, pause, and resume
foreground processes. It also provides tools to monitor and
manage the resources used by these processes, such as virtual
memory and CPU usage.
 The "ps" command can be used to list all processes or filter
the list based on various criteria, such as the user who started
the process, the process ID (PID), and the process status.

2. Background processes: Such kind of processes are also known


as non interactive processes. These are the processes that are to
be executed or initiated by the system itself or by users, though
they can even be managed by users. These processes have a unique
PID or process if assigned to them and we can initiate other
processes within the same terminal from which they are initiated.
Background process management in Linux refers to the
management of processes that run in the background and do not
require user interaction. These processes can be started by the
operating system or by a user, and they do not have an associated
terminal. Linux provides several tools for managing background
process execution.
 “ps” command can be used to filter the list of processes to
show only background processes.
 “top” command can be used to monitor the resources used by
background processes such as memory and CPU usage.

1. Example of foreground process.


sleep 5
This command will be executed in the terminal and we would be able
to execute another command after the execution of the above
command.
To stop a foreground process in between of its execution we may
press CTRL+Z to force stop it.

Stages of a Process in Linux


In Linux, a process goes through several stages during its lifetime. Understanding these stages
and checking how they run in the background is important for process management and
troubleshooting. The states of a process in Linux are as follows:

1. Created: A process is created when a program is executed. At this stage, the process is
in a "created" state, and its data structures are initialized.

2. Ready: The process enters the "ready" state when it is waiting to be assigned to a
processor by the Linux scheduler. At this stage, the process is waiting for its turn to
execute.

3. Running: The process enters the "running" state when it is assigned to a processor and
is actively executing its instructions.

4. Waiting: The process enters the "waiting" state when it is waiting for some event to
occur, such as input/output completion, a signal, or a timer. At this stage, the process is
not actively executing its instructions.

5. Terminated: The process enters the "terminated" state when it has completed its
execution or has been terminated by a signal. At this stage, the process data structures
are removed, and its resources are freed.

6. Zombie: A process enters the "zombie" state when it has completed its execution but
its parent process has not yet read its exit status. At this stage, the process details still
have an entry in the process table, but it does not execute any instructions. The zombie
process is removed from the process table when its parent process reads its exit status.

You might also like