Chapter -8 Unix/Linux Operating System:
Definition of operating system
Operating System is the system software that manages computer hardware, software resources,
and provides common services for computer programs.
Features of operating system
1) Memory management
Memory management module performs allocation and de-allocation of
memory space.
2) Processor management
It helps OS to create and delete processes.
3) Device management
It keeps tracks of all devices.
4) File management
It manages all file related activities such as organization, storage, retrieval,
naming, sharing and protection of files.
5) Security
Security modules protects the data and information of a computer system
against authorized access.
6) Job accounting
Keep track of time and resource used by various jobs and users.
7) Control over system performance
Recording delays between request for a service and response from the system.
How operating system works?
Operating system is loaded into memory when a computer is booted and remains
active as long as machine is up. After any program has completed execution, the
operating system cleans up the memory and registers and makes them available
for the next program
Examples of operating system
Microsoft Windows, UNIX, Linux, MacOS etc
Definition of UNIX
UNIX is a portable, multitasking, multiuser, time sharing operating system(OS).
Founder of UNIX
The UNIX was founded by Ken Thompson, Dennis Ritchie and Brain
kerninghan at AT& T Bell Labs research in 1969.
Founder of LINUX
Linus Benedict Torvalds in 1991.
Difference between UNIX and LINUX (linux is a unix clone)
UNIX LINUX
It is a multi tasking, multiuser operating It is a free and open source software.
system
Developed by ken Thompson, Dennis Developed by Linus Benedict Torvalds.
Ritchie and Brain Kerninghan
Source code is not available to general Source code is available to general
public. public
Not portable Portable
Solaris, HP UNIX are some versions. Ubuntu, Fedora are some versions.
Need of UNIX
Network capability:
With other OS, additional software must be purchased for networking but with
UNIX, network capability is the part of the operating system.
History of UNIX
1960 Bell labs involved in the project with MIT, General Electric and Bell
Laboratories to develop a time sharing system called
MULTICS(Multiplexed Operating and Computing System).
1969 Ken Thompson wrote the first version of the UNIX called
UNICS(Uniplexed Information and Computing System)
1970 Finally UNICS became UNIX.
Differences between UNIX and DOS
UNIX DOS
UNIX can have GUI DOS Can’t have GUI
UNIX is more secure DOS is not more secure compared to UNIX
UNIX is multitasking DOS is singletasking
UNIX are multiuser DOS is single user
UNIX is case sensitive DOS is not case sensitive
UNIX is used in servers DOS is used in embedded systems
Differences between UNIX and Windows
Windows
Windows is not an open source(paid
download) one)
UNIX has very high security system Windows has low security system
UNIX is a command based operating Windows is not a command based
system operating system
The file system is arranged in The file system is arranged in parallel
hierarchical manner manner
UNIX is not a user friendly Windows is a user friendly
Free office(such as excel, PowerPoint Pay for MS Office
and others)
Low Hardware cost High Hardware cost
Customizable add features Not customizable
Architecture of UNIX System/ UNIX System Structure
The Architecture of the UNIX system is divided into 4 major components. They are:
1) The Kernel
2) The Shell
3) Files and Processes
4) System Calls
1. The Kernel
The Kernel is the heart of the Operating System.
It interface between Shell and Hardware.
It performs Low Level Task.
Eg: Device Management, Memory Management etc.
2. The Shell
The Shell is a collection of UNIX Commands.
The Shell acts as an interface between the user and the kernel.
The Shell is a Command Line Interpreter(CLI)–Translates the commands
provided by the user and converts it into a language that is understood by
the Kernel.
Only one Kernel running on the system, but several shells in action-one for
each user who is logged in.
Eg: C Shell, Bourne Shell, Korn Shell etc.
3. Files and Processes
A File is an array of bytes and can contain anything.
All the data in UNIX is organized into files.
A Process is a program file under execution.
Files and Processes belongs to a separate hierarchical structure.
4. System Calls
UNIX is written in C.
Thousands of commands in the system uses a handful of functions called
System Calls to communicate with the kernel.
Features of UNIX
1) Simple design, organization and functioning
The architecture of the UNIX is simple, organized and functional.
2) Portability
The code can be changed and compiled on a new machine.
3) UNIX Shell
The user interface UNIX Shell provides the services that the user wants.
4) Hierarchical file system
UNIX uses a hierarchical file structure to store information.
5) Multi user
UNIX allows more than one user to share the same computer system at the
same time.
6) Multi-tasking
More than one program can be run at a time.
7) Security
UNIX provides high security level( System level security and File level
security)
8) Pipes and Filters
In UNIX, we can create complex programs from simple programs.
9) Utilities
UNIX has over 200 utility programs for various functions.
10) Machine Independence
The system hides the machine architecture from the user, making it easier to
write applications that can run any computer system.
Architecture of Kernel
The system call and library interface represent the border between
user programs and the kernel.
The File subsystem manages files, allocating file space,
administrating free space, controlling access to files and retrieving
data for users.
Kernel Interface to Hardware is responsible for handling interrupts
and for communicating with the machine.
Device drivers are the kernel modules that control the operation
of peripheral devices.
Block I/O devices are random access storage devices to reset the system.
Scheduler module allocates CPU to processes.
Memory management module controls allocation of memory.
Inter-process communication (IPC) ranges from asynchronous
signaling of events to synchronous transmission of messages between
processes.
Features of Kernel
1) Concurrency
Many processes run concurrently to improve the performance of the system.
2) Virtual Memory(VM)
Memory management subsystem implements the virtual memory and users
need not worry about the executable program size and RAM size.
3) Paging
It is a technique to minimize the internal and external fragmentation in the
physical memory.
4) Virtual File System(VFS)
A VFS is a file system used to help the user to hide the different file systems
complexities.
5) Inter process communication
Itranges from asynchronous signaling of events to synchronous transmission
of messages between processes.
Operating System Services
1) User interface
User interface refers to the software that allows a person to interact with the
computer.
2) Program execution
The system creates a special environment for that program.
3) File system manipulation
File manipulation commands manipulates the file.
4) Input/ Output operation
OS provides the capability to change where standard input comes from or
where output goes using Input/Output concept.
5) Communication
Communication commands makes proper communication between different
computers, networks and remote users.
6) Resource allocation
Resource allocation techniques allocates resources when a program need
them.
7) Error detection
Error detection techniques helps us to detect and correct errors.
8) Accounting
It helps us to maintain account details of users.
9) Security and protection
Only authorised users can access the files and directories.
What is Linux?
As a Unix-like operating system, Linux, the open-source community, manages the hardware and
resources. Similar to Windows, Mac, and other OS, the operating system forms the basis of Linux
Distros. It launches the programs and creates a connection between the user and the hardware.
Key Features of the Unix Operating System
Users use the Unix operating system for its stability, security, building block approach, and strong
file system. Below I have shown some features of this operating system:
Open Source
The source code of the Unix operating system is open and modifiable for the user. So the user can
easily modify and customize the code according to the user’s needs. It helps in the improvement of
the user.
Portability
Unix is a portable operating system that the users can use for any of the hardware architecture. It
has high compatibility that makes it usable for different hardware systems.
Structured File System
It comes with a hierarchical file structure where all files are categorized by their type and stored in a
specific directory.
UNIX Toolkit
Unix provides a host application support to enhance the facilities because all the tasks can not done
by the kernel alone.
Program Execution
The users do all the Unix commands and programs on the shell. Programmers design the shell in
such a way that makes it compatible with the programming languages.
Multiuser and Multitask System
It supports multiple users simultaneously to do different types of work. Users can do it in two ways.
1. Single users doing multiple tasks.
2. Multiple users do multiple tasks which include editing files, and using browsing facilities at
the same time.
Pattern Matching
Unix provides a special character support which is ‘*’ and by using this one can match the patterns.
Building-Block Approach
Unix uses a building block approach which means it uses a single small command for a specific job.
When one needs multiple works then he can use pipe two or more commands. This helps to filter
the data.
Documentation
Unix has strong documentation as it has manual pages that provide complete information. When
one does not understand anything then he can get help from these pages.
File Handling
The handling of the files can be easy with the use of redirection and piping. The user redirects the
input and output commands to create desired data pipelines.
Beginning of Linux
Linus Benedict Torvalds, while studying at the University of Helsinki in Finland in 1991 was 21 years
old, and he was using Minix, a non-free operating system. At that moment, he became aware of the
need for a free and open-source operating system that would forward the goals of GNU.
Key Features of the Linux Operating System
Torvalds and other developers wrote the Linux code following the Unix principle, it has many similar
features to Unix. I have shown some of the different features of Linux below:
Free Software
It is free software that is available for all user and also provide open-source support that’s why
developers and users can modify it as one’s preference. Some Unix versions are free otherwise it is
very expensive.
Multiple Language
Linux supports multiple languages on the other hand Unix only supports English.
File System
Both operating systems support hierarchical file systems. But Linux supports more file systems than
Unix.
Development of Linux
Linux is an open-source software that modified with time and released the modified versions. It is
continuously evolving and expanding which shows the continuous development of the Linux kernel.
I have shown some of the developments below:
As an open-source operating system, it developed many new features like
supporting Windows Subsystem Linux. It also improves the version of Kubernetes. For
managing the applications it develops technologies the Docker and Kubernetes.
The continuous development of the Linux distribution provides new Ubuntu versions.
Recently, the 23.04 LTS Ubuntu version has been released. It has newer features and
modules but it is not stable like 22.04 LTS because it lasts for nine months.
The programmers have made a Linux community support who use Linux and gave their
suggestions to the maintainer. It helps the maintainer to improve the efficiency of Linux. The
distributors of the project are Debian, Fedora, and OpenSUSE.
Developers have developed Linux kernel with time and the recently released Linux kernel
version 6.5 adds some new features. This kernel supports Intel TPMI, provides runnable
boosting features, and boosts the Btrfs file system.
Current Situation of Linux
The uses of Linux are increasing day by day because of its growth in cloud computing and flexibility.
Below I have shown some statistics:
Linux has around 600 distributions.
Around 80% of web servers are using Linux.
The Linux market share of this operating system is $3.89 billion.
Approximately 85% of smartphones run on Linux.
Nowadays users use Linux in embedded systems, mobile devices supercomputers, and
servers.
What is Linux Operating System and Kernel?
An operating system (OS) is a software system that manages the computer that provides some
services for computer programs and manages computer hardware and software. Basically, it is a
communication or resource allocation between computer hardware and applications. It provides
some services like managing input and output devices, managing file systems, providing UI (User
Interface) and also managing computer memory. It also governs and executes all the programs.
Linux operating System also consists of various components for example system libraries, user-
space utilities, Linux kernel, and applications. The kernel is the core component of an operating
system. This provides a platform for programs and various services to run on top of it. The Linux
kernel is modifiable according to the user’s needs. Overall, the Linux Operating System and Linux
kernel together provide a strong and user-friendly platform.
In a General-Purpose Computer running many processes simultaneously, we need a middle layer to
manage the distribution of the computer’s hardware resources efficiently and fairly among all the
various processes running on the computer. This middle layer is referred to as the kernel. The
kernel virtualizes the computer’s common hardware resources to provide each process with its own
virtual resources. This makes the process seem as if it is the sole process running on the machine.
The kernel is also responsible for preventing and mitigating conflicts between different processes.
This is schematically represented below:
Schematical representation of Kernel working
Figure: Virtual Resources for each Process
The Core Subsystems of the Linux Kernel are as follows:
1. The Process Scheduler
2. The Memory Management Unit (MMU)
3. The Virtual File System (VFS)
4. The Networking Unit
5. Inter-Process Communication Unit
Core Subsystems of the Linux Kernel Figure:
The Linux Kernel for the purpose of this article we will only be focusing on the 1st three important
subsystems of the Linux Kernel. The basic functioning of each of the 1st three subsystems is
elaborated below:
The Process Scheduler: This kernel subsystem is responsible for fairly distributing the CPU
time among all the processes running on the system simultaneously.
The Memory Management Unit: This kernel sub-unit is responsible for proper distribution
of the memory resources among the various processes running on the system. The MMU
does more than just simply provide separate virtual address spaces for each of the
processes.
The Virtual File System: This subsystem is responsible for providing a unified interface to
access stored data across different filesystems and physical storage media.
Some Basic Commands:
Some Basic Commands we need to know while working on Linux Kernel.
`ls` : Use to list all the files and directories in a particular location specified by us.
SYSTEM CALLS
In computing, a system call is the programmatic way in which a computer program requests a
service from the kernel of the operating system it is executed on. • Asystem call is a way for
programs to interact with the operating system.
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
File structure related system calls • These calls return a file descriptor that identifies the I/O
channel. • creat() • open() • close() • read() • write() • lseek()
Directory Structure
Unix uses a hierarchical file system structure, much like an upside-down tree, with root (/) at the
base of the file system and all other directories spreading from there.
A Unix filesystem is a collection of files and directories that has the following properties −
It has a root directory (/) that contains other files and directories.
Each file or directory is uniquely identified by its name, the directory in which it resides, and
a unique identifier, typically called an inode.
By convention, the root directory has an inode number of 2 and the lost+found directory has
an inode number of 3. Inode numbers 0 and 1 are not used. File inode numbers can be seen
by specifying the -i option to ls command.
It is self-contained. There are no dependencies between one filesystem and another.
The directories have specific purposes and generally hold the same types of information for easily
locating files. Following are the directories that exist on the major versions of Unix −
[Link]
Directory & Description
.
/root
1 This is the root directory which should contain only the directories needed at the top
level of the file structure
/bin
2
This is where the executable files are located. These files are available to all users
/dev
3
These are device drivers
/etc
4 Supervisor directory commands, configuration files, disk configuration files, valid user
lists, groups, ethernet, hosts, where to send critical messages
/lib
5
Contains shared library files and sometimes other kernel-related files
/boot
6
Contains files for booting the system
/home
7
Contains the home directory for users and other accounts
8 /mnt
Used to mount other temporary file systems, such as cdrom and floppy for the CD-
ROM drive and floppy diskette drive, respectively
/proc
9 Contains all processes marked as a file by process number or other information that is
dynamic to the system
/tmp
10
Holds temporary files used between system boots
/usr
11 Used for miscellaneous purposes, and can be used by many users. Includes
administrative commands, shared files, library files, and others
/var
12 Typically contains variable-length files such as log and print files and any other type of
file that may contain a variable amount of data
/sbin
13 Contains binary (executable) files, usually for system administration. For
example, fdisk and ifconfig utlities
/kernel
14
Contains kernel files
Navigating the File System
Now that you understand the basics of the file system, you can begin navigating to the files you
need. The following commands are used to navigate the system −
[Link]. Command & Description
cat filename
1
Displays a filename
2 cd dirname
Moves you to the identified directory
cp file1 file2
3
Copies one file/directory to the specified location
file filename
4
Identifies the file type (binary, text, etc)
find filename dir
5
Finds a file/directory
head filename
6
Shows the beginning of a file
less filename
7
Browses through a file from the end or the beginning
ls dirname
8
Shows the contents of the directory specified
mkdir dirname
9
Creates the specified directory
more filename
10
Browses through a file from the beginning to the end
mv file1 file2
11
Moves the location of, or renames a file/directory
pwd
12
Shows the current directory the user is in
13 rm filename
Removes a file
rmdir dirname
14
Removes a directory
tail filename
15
Shows the end of a file
touch filename
16
Creates a blank file or modifies an existing file or its attributes
whereis filename
17
Shows the location of a file
which filename
18
Shows the location of a file if it is in your PATH
The df Command
The first way to manage your partition space is with the df (disk free) command. The command df -k
(disk free) displays the disk space usage in kilobytes, as shown below −
$df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vzfs 10485760 7836644 2649116 75% /
/devices 0 0 0 0% /devices
Some of the directories, such as /devices, shows 0 in the kbytes, used, and avail columns as well as
0% for capacity. These are special (or virtual) file systems, and although they reside on the disk
under /, by themselves they do not consume disk space.
The df -k output is generally the same on all Unix systems. Here's what it usually includes −
[Link]. Column & Description
1 Filesystem
The physical file system name
kbytes
2
Total kilobytes of space available on the storage medium
used
3
Total kilobytes of space used (by files)
avail
4
Total kilobytes available for use
capacity
5
Percentage of total space used by files
Mounted on
6
What the file system is mounted on
You can use the -h (human readable) option to display the output in a format that shows the size in
easier-to-understand notation.
The du Command
The du (disk usage) command enables you to specify directories to show disk space usage on a
particular directory.
This command is helpful if you want to determine how much space a particular directory is taking.
The following command displays number of blocks consumed by each directory. A single block may
take either 512 Bytes or 1 Kilo Byte depending on your system.
$du /etc
10 /etc/cron.d
126 /etc/default
6 /etc/dfs
...
The -h option makes the output easier to comprehend −
$du -h /etc
5k /etc/cron.d
63k /etc/default
3k /etc/dfs
...
Mounting the File System
A file system must be mounted in order to be usable by the system. To see what is currently
mounted (available for use) on your system, use the following command −
$ mount
/dev/vzfs on / type reiserfs (rw,usrquota,grpquota)
proc on /proc type proc (rw,nodiratime)
devpts on /dev/pts type devpts (rw)
The /mnt directory, by the Unix convention, is where temporary mounts (such as CDROM drives,
remote network drives, and floppy drives) are located. If you need to mount a file system, you can
use the mount command with the following syntax −
mount -t file_system_type device_to_mount directory_to_mount_to
For example, if you want to mount a CD-ROM to the directory /mnt/cdrom, you can type −
$ mount -t iso9660 /dev/cdrom /mnt/cdrom
This assumes that your CD-ROM device is called /dev/cdrom and that you want to mount it
to /mnt/cdrom. Refer to the mount man page for more specific information or type mount -h at the
command line for help information.
After mounting, you can use the cd command to navigate the newly available file system through
the mount point you just made.
Unmounting the File System
To unmount (remove) the file system from your system, use the umount command by identifying
the mount point or device.
For example, to unmount cdrom, use the following command −
$ umount /dev/cdrom
The mount command enables you to access your file systems, but on most modern Unix systems,
the automount function makes this process invisible to the user and requires no intervention.
User and Group Quotas
The user and group quotas provide the mechanisms by which the amount of space used by a single
user or all users within a specific group can be limited to a value defined by the administrator.
Quotas operate around two limits that allow the user to take some action if the amount of space or
number of disk blocks start to exceed the administrator defined limits −
Soft Limit − If the user exceeds the limit defined, there is a grace period that allows the user
to free up some space.
Hard Limit − When the hard limit is reached, regardless of the grace period, no further files
or blocks can be allocated.
There are a number of commands to administer quotas −
[Link]
Command & Description
.
quota
1
Displays disk usage and limits for a user of group
edquota
2
This is a quota editor. Users or Groups quota can be edited using this command
quotacheck
3
Scans a filesystem for disk usage, creates, checks and repairs quota files
setquota
4
This is a command line quota editor
quotaon
5 This announces to the system that disk quotas should be enabled on one or more
filesystems
quotaoff
6 This announces to the system that disk quotas should be disabled for one or more
filesystems
7 repquota
This prints a summary of the disc usage and quotas for the specified file systems
Root account
This is also called superuser and would have complete and unfettered control of the system. A
superuser can run any commands without any restriction. This user should be assumed as a system
administrator.
System accounts
System accounts are those needed for the operation of system-specific components for example
mail accounts and the sshd accounts. These accounts are usually needed for some specific function
on your system, and any modifications to them could adversely affect the system.
User accounts
User accounts provide interactive access to the system for users and groups of users. General users
are typically assigned to these accounts and usually have limited access to critical system files and
directories.
Unix supports a concept of Group Account which logically groups a number of accounts. Every
account would be a part of another group account. A Unix group plays important role in handling
file permissions and process management.
Managing Users and Groups
There are four main user administration files −
/etc/passwd − Keeps the user account and password information. This file holds the majority
of information about accounts on the Unix system.
/etc/shadow − Holds the encrypted password of the corresponding account. Not all the
systems support this file.
/etc/group − This file contains the group information for each account.
/etc/gshadow − This file contains secure group account information.
Check all the above files using the cat command.
The following table lists out commands that are available on majority of Unix systems to create and
manage accounts and groups −
[Link]. Command & Description
useradd
1
Adds accounts to the system
usermod
2
Modifies account attributes
userdel
3
Deletes accounts from the system
groupadd
4
Adds groups to the system
groupmod
5
Modifies group attributes
groupdel
6
Removes groups from the system
Create a Group
We will now understand how to create a group. For this, we need to create groups before creating
any account otherwise, we can make use of the existing groups in our system. We have all the
groups listed in /etc/groups file.
All the default groups are system account specific groups and it is not recommended to use them
for ordinary accounts. So, following is the syntax to create a new group account −
groupadd [-g gid [-o]] [-r] [-f] groupname
The following table lists out the parameters −
[Link]
Option & Description
.
-g GID
1
The numerical value of the group's ID
2 -o
This option permits to add group with non-unique GID
-r
3
This flag instructs groupadd to add a system account
-f
4 This option causes to just exit with success status, if the specified group already exists.
With -g, if the specified GID already exists, other (unique) GID is chosen
groupname
5
Actual group name to be created
If you do not specify any parameter, then the system makes use of the default values.
Following example creates a developers group with default values, which is very much acceptable
for most of the administrators.
$ groupadd developers
Modify a Group
To modify a group, use the groupmod syntax −
$ groupmod -n new_modified_group_name old_group_name
To change the developers_2 group name to developer, type −
$ groupmod -n developer developer_2
Here is how you will change the financial GID to 545 −
$ groupmod -g 545 developer
Delete a Group
We will now understand how to delete a group. To delete an existing group, all you need is
the groupdel command and the group name. To delete the financial group, the command is −
$ groupdel developer
This removes only the group, not the files associated with that group. The files are still accessible by
their owners.
Create an Account
Let us see how to create a new account on your Unix system. Following is the syntax to create a
user's account −
useradd -d homedir -g groupname -m -s shell -u userid accountname
The following table lists out the parameters −
[Link]. Option & Description
-d homedir
1
Specifies home directory for the account
-g groupname
2
Specifies a group account for this account
-m
3
Creates the home directory if it doesn't exist
-s shell
4
Specifies the default shell for this account
-u userid
5
You can specify a user id for this account
accountname
6
Actual account name to be created
If you do not specify any parameter, then the system makes use of the default values.
The useradd command modifies the /etc/passwd, /etc/shadow, and /etc/group files and creates a
home directory.
Following is the example that creates an account mcmohd, setting its home directory
to /home/mcmohd and the group as developers. This user would have Korn Shell assigned to it.
$ useradd -d /home/mcmohd -g developers -s /bin/ksh mcmohd
Before issuing the above command, make sure you already have the developers group created
using the groupadd command.
Once an account is created you can set its password using the passwd command as follows −
$ passwd mcmohd20
Changing password for user mcmohd20.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
When you type passwd accountname, it gives you an option to change the password, provided you
are a superuser. Otherwise, you can change just your password using the same command but
without specifying your account name.
Modify an Account
The usermod command enables you to make changes to an existing account from the command
line. It uses the same arguments as the useradd command, plus the -l argument, which allows you
to change the account name.
For example, to change the account name mcmohd to mcmohd20 and to change home directory
accordingly, you will need to issue the following command −
$ usermod -d /home/mcmohd20 -m -l mcmohd mcmohd20
Delete an Account
The userdel command can be used to delete an existing user. This is a very dangerous command if
not used with caution.
There is only one argument or option available for the command .r, for removing the account's
home directory and mail file.
For example, to remove account mcmohd20, issue the following command −
$ userdel -r mcmohd20
If you want to keep the home directory for backup purposes, omit the -r option. You can remove
the home directory as needed at a later time.