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

Unit 4

The document discusses concepts related to file systems and information management in operating systems. It covers topics like file concepts, file structures, file support, directory structures including single-level, two-level, tree-structured and acyclic graph directories. It also discusses file allocation strategies, protection goals, and a case study on the UNIX file system.

Uploaded by

Bipin Singh
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 views66 pages

Unit 4

The document discusses concepts related to file systems and information management in operating systems. It covers topics like file concepts, file structures, file support, directory structures including single-level, two-level, tree-structured and acyclic graph directories. It also discusses file allocation strategies, protection goals, and a case study on the UNIX file system.

Uploaded by

Bipin Singh
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/ 66

Madan Mohan Malaviya Univ.

of Technology, Gorakhpur

Operating System Concepts (MCA-204)


Unit 4

Department of Information Technology &


Computer Application, Madan Mohan Malaviya
University of Technology
Gorakhpur-273010,India
21-05-2023 Side 1
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Content
Information Management: File concept, file support, directory
structures, symbolic file directory, basic file directory, logical file
system, physical file system, access methods, file protection, file
allocation strategies. Protection: Goals, policies and mechanisms,
domain of protection, access matrix and its implementation, access
lists, capability lists, Lock/Key mechanisms, passwords, dynamic
protection scheme, security concepts and public and private keys, RSA
encryption and decryption algorithms.
A case study: A UNIX OS file system, shell, filters, shell
programming, programming with the standard I/O, UNIX system calls.

21-05-2023 Side 2
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Information Management

 Information management is a cycle of processes that support the


organization's learning activities: identifying information needs, acquiring
information, organizing and storing information, developing information
products and services, distributing information, and using information

21-05-2023 Side 3
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

File Concept
 A file is a named collection of related information that is recorded on secondary
storage such as magnetic disks, magnetic tapes and optical disks. In general, a file is a
sequence of bits, bytes, lines or records whose meaning is defined by the files creator
and user.
File Structure
A File Structure should be according to a required format that the operating system can
understand.
 A file has a certain defined structure according to its type.
 A text file is a sequence of characters organized into lines.
 A source file is a sequence of procedures and functions.
 An object file is a sequence of bytes organized into blocks that are understandable by
the machine.
 When operating system defines different file structures, it also contains the code to
support these file structure. Unix, MS-DOS support minimum number of file
21-05-2023
structure. Side 4
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

File Support
 A file has a name and data. Moreover, it also stores meta information like file
creation date and time, current size, last modified date, etc. All this information is
called the support of a file system. Here, are some important File support used in
OS:
 Name: It is the only information stored in a human-readable form.
 Identifier: Every file is identified by a unique tag number within a file system
known as an identifier.
 Location: Points to file location on device.
 Type: This attribute is required for systems that support various types of files.
 Size: Attribute used to display the current file size.
 Protection: This attribute assigns and controls the access rights of reading,
writing, and executing the file.
 Time, date and security: It is used for protection, security, and also used for
21-05-2023
monitoring Side 5
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Directory Structures
 A Directory is the collection of the correlated files on the disk. In simple
words, a directory is like a container which contains file and folder. In a
directory, we can store the complete file attributes or some attributes of the
file. A directory can be comprised of various files. With the help of the
directory, we can maintain the information related to the files.

21-05-2023 Side 6
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 There are various types of information which are stored in a directory:


1. Name: – Name is the name of the directory, which is visible to the user.
2. Type: – Type of a directory means what type of directory is present such as single-
level directory, two-level directory, tree-structured directory, and Acyclic graph
directory.
3. Location: – Location is the location of the device where the header of a file is
located.
4. Size: – Size means number of words/blocks/bytes in the file.
5. Position: – Position means the position of the next-read pointer and the next-write
pointer.
6. Protection: – Protection means access control on the read/write/delete/execute.
7. Usage: – Usage means the time of creation, modification, and access, etc.
8. Mounting: – Mounting means if the root of a file system is grafted into the
existing tree of other file systems.
21-05-2023 Side 7
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Types of Directory Structure
 There are various types of directory structure:
Single-Level Directory ,Two-Level Directory, Tree-Structured Directory, Acyclic
Graph Directory, General-Graph Directory
Single-Level Directory: – Single-Level Directory is the easiest directory structure.
There is only one directory in a single-level directory, and that directory is called a
root directory. In a single-level directory, all the files are present in one directory that
makes it easy to understand. In this, under the root directory, the user cannot create
the subdirectories.

21-05-2023 Side 8
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Two-Level Directory
 Two-Level Directory is another type of directory structure. In this, it is possible to
create an individual directory for each of the users. There is one master node in the
two-level directory that include an individual directory for every user. At the
second level of the directory, there is a different directory present for each of the
users. Without permission, no user can enter into the other user’s directory.

21-05-2023 Side 9
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Tree-Structured Directory
 In a tree-structured directory, there is an own directory of each user, and any user
is not allowed to enter into the directory of another user. Although the user can
read the data of root, the user cannot modify or write it. The system administrator
only has full access to the root directory. In this, searching is quite effective and
we use the current working concept. We can access the file by using two kinds of
paths, either absolute or relative.

21-05-2023 Side 10
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Acyclic-Graph Directory
 In the tree-structure directory, the same files cannot exist in the multiple
directories, so sharing the files is the main problem in the tree-structure directory.
With the help of the acyclic-graph directory, we can provide the sharing of files.
In the acyclic-graph directory, more than one directory can point to a similar file
or subdirectory. We can share those files among the two directory entries.
 With the help of aliases, and links, we can create this type of directory graph. We
may also have a different path for the same file. Links may be of two kinds, which
are hard link (physical) and symbolic (logical).
 If we delete the files in acyclic graph structures, then
1. In the hard link (physical) case, we can remove the actual files only if all the
references to the file are deleted.
2. In the symbolic link (logical) case, we just delete the file, and there is only a
dangling point that is left.

21-05-2023 Side 11
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

General-Graph Directory
 The General-Graph directory is another vital type of directory structure. In this
type of directory, within a directory we can create cycle of the directory where we
can derive the various directory with the help of more than one parent directory.
 The main issue in the general-graph directory is to calculate the total space or size,
taken by the directories and the files.

21-05-2023 Side 12
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Symbolic File Directory


 SFS stores files from a variety of sources, aka collections, that may include
directories and removable media, as symbolic links to the source files. It also
stores the metadata of the source files so that files can later be queried
without having to plug in the source media.
 An SFS is a managed directory which is initialized with the command: sfs
init. All commands to be executed in the context of an individual SFS must
be run from within the SFS directory tree. Files are added using the
command sfs add-col my_collection /path/to/source (add collection). SFS
Files are sym links to source files in added collections. Foreign links and
other files can also exist in an SFS but they are not managed by it and are
mostly ignored.

21-05-2023 Side 13
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Basic File Directory

 It refers to the ability of the operating system to differentiate various types of


files like text files, binary, and source files. However, Operating systems like
MS_DOS and UNIX has the following type of files:
Character Special File
 It is a hardware file that reads or writes data character by character, like mouse,
printer, and more.
Ordinary files
 These types of files stores user information.
 It may be text, executable programs, and databases.
 It allows the user to perform operations like add, delete, and modify.

21-05-2023 Side 14
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Directory Files
 Directory contains files and other related information about those files. Its
basically a folder to hold and organize multiple files.
Special Files
 These files are also called device files. It represents physical devices like
printers, disks, networks, flash drive, etc.

21-05-2023 Side 15
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

logical File System

 Logical files do not contain data. They contain a description of records that are
found in one or more physical files. A logical file is a view or representation of
one or more physical files. Logical files that contain more than one format are
referred to as multi-format logical files.
 If your program processes a logical file which contains more than one record
format, you can use the _Rformat() function to set the format you wish to use.
Some operations cannot be performed on logical files. If you open a logical file
for stream file processing with open modes W, W+, WB or WB+, the file is
opened but not cleared. If you open a logical file for record file processing with
open modes WR or WR+, the file is opened but not cleared. Records in i Series
database files can be described using either a field level description or record
level description.

21-05-2023 Side 16
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Physical File System


 Physical files contain the actual data that is stored on an i Series system, and a
description of how data is to be presented to or received from a program.
They contain only one record format, and one or more members. Records in
database files can be described using either a field level description or record
level description.
 A field-level description describes the fields in the record to the system.
Database files that are created with field level descriptions are referred to as
externally described files. A record-level description describes only the length
of the record, and not the contents of the record. Database files that are
created with record level descriptions are referred to as program-described
files. This means that your ILE C/C++ program must describe the fields in the
record.

21-05-2023 Side 17
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access Methods
 The file contains the information but when it required to used this information
can be access by the access methods and reads into the computer memory.
Some system provides only one access method and some provide more than on
access method to access the file.
Sequential Access Method
 A sequential access is that in which the records are accessed in some sequence,
i.e., the information in the file is processed in order, one record after the other.
This access method is the most primitive one.
 The idea of sequential access is based on the tape model which is a sequential
access device. We consider sequential access method is best because most of
the records in a file are to be processed. For example, transaction files.

21-05-2023 Side 18
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Direct or Random Access Methods


 Sometimes it is not necessary to process every record in a file. It is not necessary
to process all the records in the order in which they are present in the memory. In
all such cases, direct access is used.
 The disk is a direct access device which gives us the reliability to random access
of any file block. In the file, there is a collection of physical blocks and the
records of that blocks.
 Eg. Databases are often of this type since they allow query processing that
involves immediate access to large amounts of information. All reservation
systems fall into this category.
 Not all operating systems support direct access files. The sequential and direct
access of the file is defined at the time of creation and accessed accordingly later.
The direct access of a sequential file is not possible but Sequential access to a
direct access file is possible.

21-05-2023 Side 19
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Index Access Method


 An indexed file is a computer file with an index that allows easy random
access to any record given its file key. The key is an attribute that uniquely
identifies a record. We can say that If more than one index is present the
other ones are alternate indexes. The creation of the indexes is done with
the file but maintained by the system.

21-05-2023 Side 20
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

File Protection
 In computer systems, alot of user’s information is stored, the objective of the
operating system is to keep safe the data of the user from the improper access to
the system. Protection can be provided in number of ways.
Types of Access :
 The files which have direct access of the any user have the need of protection.
The files which are not accessible to other users doesn’t require any kind of
protection. The mechanism of the protection provide the facility of the
controlled access by just limiting the types of access to the file. Access can be
given or not given to any user depends on several factors, one of which is the
type of access required. Several different types of operations can be controlled:

21-05-2023 Side 21
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 Read – Reading from a file.


 Write – Writing or rewriting the file.
 Execute – Loading the file and after loading the execution process starts.
 Append – Writing the new information to the already existing file, editing must be end
at the end of the existing file.
 Delete – Deleting the file which is of no use and using its space for the another data.
 List – List the name and attributes of the file.
Other Protection Approaches:
 The access to any system is also controlled by the password.
 The number of passwords are very large so it is difficult to remember the large
passwords.
 If one password is used for all the files, then once it is discovered, all files are accessible.

21-05-2023 Side 22
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
File Allocation Strategies
The allocation methods define how the files are stored in the disk blocks. There are
three main disk space or file allocation methods:
1) Contiguous Allocation
2) Linked Allocation
3) Indexed Allocation
Contiguous Allocation
 In this scheme, each file occupies a contiguous set of blocks on the disk. For
example, if a file requires n blocks and is given a block b as the starting location,
then the blocks assigned to the file will be: b, b+1, b+2,……b+n-1. This means that
given the starting block address and the length of the file (in terms of blocks
required), we can determine the blocks occupied by the file.
 The directory entry for a file with contiguous allocation contains address of starting
block length of the allocated portion.

21-05-2023 Side 23
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 The file ‘mail’ in the following figure starts from the block 19 with length = 6
blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks.

21-05-2023 Side 24
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Advantages:
 Both the Sequential and Direct Accesses are supported by this.
 This is extremely fast because of contiguous allocation of file blocks.
Disadvantages:
 This method suffers from both internal and external fragmentation.
 Increasing file size is difficult because it depends on the availability of
contiguous memory at a particular instance.

21-05-2023 Side 25
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Linked List Allocation


 In this scheme, each file is a linked list of disk blocks which need not be
contiguous. The disk blocks can be scattered anywhere on the disk.
 The directory entry contains a pointer to the starting and the ending file block. Each
block contains a pointer to the next block occupied by the file.
 The file ‘jeep’ in following image shows how the blocks are randomly distributed.
The last block (25) contains -1 indicating a null pointer and does not point to any
other block.

21-05-2023 Side 26
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Advantages:
 This is very flexible in terms of file size. File size can be increased easily .
 This method does not suffer from external fragmentation. This makes it relatively
better in terms of memory utilization.
Disadvantages:
 It does not support random or direct access. We can not directly access the blocks
of a file.

21-05-2023 Side 27
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Indexed Allocation
 In this scheme, a special block known as the Index block contains the pointers to
all the blocks occupied by a file. Each file has its own index block. The ith entry in
the index block contains the disk address of the ith file block. The directory entry
contains the address of the index block as shown in the image:

21-05-2023 Side 28
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Advantages:
 This supports direct access to the blocks occupied by the file and therefore
provides fast access to the file blocks.
 It overcomes the problem of external fragmentation.
Disadvantages:
 The pointer overhead for indexed allocation is greater than linked allocation.

21-05-2023 Side 29
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Protection

 Protection refers to a mechanism which controls the access of programs,


processes, or users to the resources defined by a computer system. We can
take protection as a helper to multi programming operating system, so that
many users might safely share a common logical name space such as
directory or files.
Need of Protection:
 To prevent the access of unauthorized users.
 To improve reliability by detecting errors.

21-05-2023 Side 30
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Role of Protection:
 The role of protection is to provide a mechanism that implement policies which
defines the uses of resources in the computer system. Some policies are defined
at the time of design of the system, some are designed by management of the
system and some are defined by the users of the system to protect their own
files and programs.
 Every application has different policies for use of the resources and they may
change over time so protection of the system is not only concern of the designer
of the operating system. Application programmer should also design the
protection mechanism to protect their system against misuse.
 Policy is different from mechanism. Mechanisms determine how something will
be done and policies determine what will be done. Policies are changed over
time and place to place.

21-05-2023 Side 31
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Goals
 The role of protection in a computer system is to provide a mechanism
for the enforcement of the policies governing resource use. These
policies can be established in a variety of ways. Some are fixed in the
design of the system, while others are formulated by the management
of a system. Still others are defined by the individual users to protect
their own files and programs. A protection system must have the
flexibility to enforce a variety of policies.

21-05-2023 Side 32
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Policies and Mechanisms


 The time-tested guiding principle for protection is the Principle of least
privilege. It dictates that programs, users, and even systems be given just
enough privileges to perform their tasks.
 An operating system following the principle of least privilege implements its
features, programs, system calls, and data structures so that failure or
compromise of a component does the minimum damage.
 The principle of least privilege can help produce a more secure computing
environment.

21-05-2023 Side 33
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Protection Mechanisms
 Protection plays a very crucial role in a multiuser environment, where several
users will be making concurrent use of the computer resources such as CPU,
memory etc. It is the duty of the operating system to provide a mechanism that
protects each process from others.
 All the items that require protection in a multiuser environment are down as
objects and those that want to access these objects are known as subjects. The
operating system grants different 'access rights' to different subjects.
 These rights may include read, write, execute, append, delete etc.

21-05-2023 Side 34
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Domain
 A domain is a combination of different objects and a set of different 'access rights'
that can be granted to different subjects to operate on each of these objects. An
operating system maintains several such domains with different combinations of
access rights. The user processes can execute in one of those domains and can
access the objects in that domain according to the access rights given to those
objects.

fig: Protection domain


 A user process executing in domain 0 has access to read from, write into and
execute the file 0 and can write to printer P0. Similarly, the process executing in
domain 1 has access to read from file 1. The printer P1 is common to both domain 1
and domain 2. The processes executing in domain 1 and domain 2 both can have
access to printer P1
21-05-2023 Side 35
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Implementation of Access Matrix
The access matrix can be implemented by using either access control lists or capability
lists.

Fig: Protection matrix


 In ACL, the data is stored by column by the operating system. The information about
the users and their access rights for each file is maintained by the operating system. The
empty entries are discarded.
 In capability lists, the access control matrix is sliced horizontally by a row. This implies
that the operating system will have to maintain for each user a list of all the objects that
the user can access and the ways in which he can access them. A combination of ACL
21-05-2023 and capability list techniques may also be used to design protection mechanisms. Side 36
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Encryption
 It is one of the most powerful and important tools of protection. The process of
encryption involves two steps: encryption of the original data into some other form
about which nothing is known to the third person and decryption of the data into the
original form the encrypted form.
 The most commonly used methods to achieve encryption are: transposition ciphers
and substitution ciphers.
 In transposition ciphers, the letters in the original message are not changed; only the
order in which they are contained in the original message gets changed.
 The set of characters in the encrypted form will be different from the original ones
if we use substitution ciphers every letter may be replaced by its previous alphabet,
for instance.
 The key idea behind the encryption schemes is that the encryption process must be
restorable. Means, once we encrypt the original message to a different form, there
should be a way to restore it to the original form.
21-05-2023 Side 37
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Example: PT : MEET ME AT THE SCHOOL HOUSE.


SOLUTION: M E M A T E C O L O S
E TE T HSHOHUE
CT: MEMATECOLOSETETHSHOHUE

Decrypt: CT: MEMATECOLOSETETHSHOHUE


MEMATECOLOS
ETETHSHOHUE
PT : MEET ME AT THE SCHOOL HOUSE.

21-05-2023 Side 38
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Domain of Protection
 A computer system is a collection of processes and objects. By objects,
we mean both hardware objects (such as the CPU, printer) and software
objects(such as files, programs).
 Each object has a unique name that differentiates it from all other objects
in the system, and each can be accessed only through well-defined and
meaningful operations.
 A process should be allowed to access only those resources for which it
has authorization Furthermore, at any time, a process should be able to
access only those resources that it currently requires to complete its task.

21-05-2023 Side 39
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access Matrix and Its Implementation
 Access Matrix is a security model of protection state in computer system. It is represented
as a matrix. Access matrix is used to define the rights of each process executing in the
domain with respect to each object. The rows of matrix represent domains and columns
represent objects. Each cell of matrix represents set of access rights which are given to the
processes of domain means each entry(i , j) defines the set of operations that a process
executing in domain Di can invoke on object Oj.

21-05-2023 Side 40
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 According to the above matrix: there are four domains and four objects- three
files(F1, F2, F3) and one printer. A process executing in D1 can read files F1
and F3. A process executing in domain D4 has same rights as D1 but it can also
write on files. Printer can be accessed by only one process executing in domain
D2. The mechanism of access matrix consists of many policies and semantic
properties. Specifically, We must ensure that a process executing in domain Di
can access only those objects that are specified in row i.
 Policies of access matrix concerning protection involve which rights should be
included in the (i, j) th entry. We must also decide the domain in which each
process executes. This policy is usually decided by the operating system. The
Users decide the contents of the access-matrix entries.

21-05-2023 Side 41
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 Association between the domain and processes can be either static or dynamic. Access
matrix provides an mechanism for defining the control for this association between domain
and processes. When we switch a process from one domain to another, we execute a switch
operation on an object(the domain). We can control domain switching by including
domains among the objects of the access matrix. Processes should be able to switch from
one domain (Di) to another domain (Dj) if and only is a switch right is given to access(i , j).

21-05-2023 Side 42
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 According to the matrix: a process executing in domain D2 can switch to


domain D3 and D4. A process executing in domain D4 can switch to domain
D1 and process executing in domain D1 can switch to domain D2.

21-05-2023 Side 43
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Access lists

 Access-list (ACL) is a set of rules defined for controlling the network


traffic and reducing network attack. ACLs are used to filter traffic based on
the set of rules defined for the incoming or out going of the network.
ACL features –
 The set of rules defined are matched serial wise i.e. matching starts with the
first line, then 2nd, then 3rd and so on.
 The packets are matched only until it matches the rule. Once a rule is
matched then no further comparison takes place and that rule will be
performed.
 There is an implicit deny at the end of every ACL, i.e., if no condition or
rule matches then the packet will be discarded.

21-05-2023 Side 44
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Types of ACL –
There are two main different types of Access-list namely:
 Standard Access-list – These are the Access-list which are made using the
source IP address only. These ACLs permit or deny the entire protocol suite.
They don’t distinguish between the IP traffic such as TCP, UDP, Https etc. By
using numbers 1-99 or 1300-1999, router will understand it as a standard ACL
and the specified address as source IP address.
 Extended Access-list – These are the ACL which uses both source and
destination IP address. In these type of ACL, we can also mention which IP
traffic should be allowed or denied. These use range 100-199 and 2000-2699.

21-05-2023 Side 45
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Capability lists
 A capability is a token, ticket, or key that gives the possessor permission to
access an entity or object in a computer system.
 A capability can be thought of as a pair (x, r) where x is the name of an
object and r is a set of privileges or rights. With each subject we can store
that subject's capabilities.
 Capability is completely transferable; it doesn't matter who presents the
capability.

21-05-2023 Side 46
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Lock/Key Mechanisms
 The Lock variable mechanism is a synchronization mechanism that is
implemented in a user mode. It is a software procedure.
 In the lock variable mechanism, we use a lock variable, i.e., Lock. There are
two values of Lock variable, which are 1 and 0. If the value of Lock is 1, then
it means the critical section is occupied, but if the value of lock is 0, then it
means the critical section is empty.
 If a process wants to enter into the critical section, then first the process checks
the value of Lock variable, and if the value of lock is 0, then we set the value
of lock as 1, and after setting the value, the process enters into the critical
section. Otherwise, the process waits for its turn.

21-05-2023 Side 47
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
 The Pseudo code of the lock variable mechanism is:

 In the following Pseudo code, we have three sections, i.e., Entry section,
Critical section, and the exit section.
 Initially, the value of the lock variable was 0. When any process wishes to
enter into the critical section, it checks the condition of the while loop. It
continuously waits until the value of the lock variable is 1. Because to enter,
the value of lock variable should be 1. So, it is clear that initially, the critical
section is empty, and thus the process enters into the critical section, and the
value of the lock variable sets to1. This means another process will wait until
the value becomes 0. In the exit section, we will reset the value of lock variable
as 0 when the process will exit from the critical section.
21-05-2023 Side 48
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Passwords

 A password is a string of characters used for authenticating a user on a


computer system. For example, you may have an account on your computer
that requires you to log in. In order to successfully access your account, you
must provide a valid username and password. This combination is often
referred to as a login. While usernames are generally public information,
passwords are private to each user.
 Most passwords are comprised of several characters, which can typically
include letters, numbers, and most symbols, but not spaces. While it is good
to choose a password that is easy to remember, you should not make it so
simple that others can guess it. The most secure passwords use a
combination of letters and numbers.

21-05-2023 Side 49
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Security Concepts and Public and Private Keys

 In Private key, the same key (secret key) is used for encryption and
decryption. In this key the only one key is copy or share by another party
to decrypt the cipher text. It is faster than the public key cryptography.
 In Public key, two keys are used for encryption and another key is used
for decryption. One key (public key) is used for encrypt the plain text to
convert it into cipher text and another key (private key) is used by
receiver to decrypt the cipher text to read the message.

21-05-2023 Side 50
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Now, we see the difference between them:
S.NO Private Key Public Key
1. Private key is faster than public key. It is slower than private key.
In this, the same key (secret key) and In public key cryptography, two keys are
2. algorithm is used to encrypt and decrypt used, one key is used for encryption and
the message. while the other is used for decryption.
In private key cryptography, the key is In public key cryptography, one of the two
3.
kept as a secret. keys is kept as a secret.
Private key is Symmetrical because Public key is Asymmetrical because there
4. there is only one key that is called secret are two types of key: private and public
key. key.
In this cryptography, sender and In this cryptography, sender and receiver
5.
receiver need to share the same key. does not need to share the same key.

In this cryptography, public key can be


6. In this cryptography, the key is private.
public and private key is private.
21-05-2023 Side 51
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

RSA Encryption and Decryption Algorithms


 RSA is the most common public-key algorithm, named after its inventors Rivest, Shamir, and
Adelman (RSA).
RSA algorithm uses the following procedure to generate public and private keys:
1) Select two large prime numbers, p and q.
2) Calculate n = p x q, where n is called the modulus for encryption and decryption.
3) Calculate φ (n) = ( p – 1) * ( q – 1)
4) Choose a number ’e ’ such that 1 < e < φ (n) where e is co prime to φ (n) , gcd ( e , φ (n) ) = 1
5) Calculate d , such that de = 1 mod φ (n)
6) Public key ‘e’ and Private Key ‘d’

21-05-2023 Side 52
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

21-05-2023 Side 53
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

A UNIX OS File System


 Unix file system is a logical method of organizing and storing large amounts of
information in a way that makes it easy to manage. A file is a smallest unit in which
the information is stored. Unix file system has several important features. All data in
Unix is organized into files. All files are organized into directories. These directories
are organized into a tree-like structure called the file system.
 Files in Unix System are organized into multi-level hierarchy structure known as a
directory tree. At the very top of the file system is a directory called “root” which is
represented by a “/”.

21-05-2023 Side 54
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Directories or Files and their Description –
 / : The slash / character alone denotes the root of the file system tree.
 /bin : Stands for “binaries” and contains certain fundamental utilities which are
generally needed by all users.
 /boot : Contains all the files that are required for successful booting process.
 /dev : Stands for “devices”. Contains file representations of peripheral devices
and pseudo-devices.
 /etc : Contains system-wide configuration files and system databases.
 /home : Contains the home directories for the users.
 /lib : Contains system libraries, and some critical files such as kernel modules
or device drivers.

21-05-2023 Side 55
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 /media : Default mount point for removable devices, such as USB sticks,
media players, etc.
 /mnt : Stands for “mount”. Contains file system mount points.
 /proc : procfs virtual file system showing information about processes as
files.
 /root : The home directory for the super user “root” – that is, the system
administrator.
 /tmp : A place for temporary files.
 /usr : Originally the directory holding user home directories, its use has
changed.
 /usr/bin : This directory stores all binary programs distributed with the
operating system.

21-05-2023 Side 56
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 /usr/include : Stores the development headers used throughout the system.


Header files are mostly used by the #include directive in C/C++ programming
language.
 /usr/lib : Stores the required libraries and data files for programs stored within
/usr or elsewhere.
 /var : A short for “variable.” A place for files that may change often – especially
in size
 /var/log : Contains system log files.
 /var/mail : The place where all the incoming mails are stored.
 /var/spool : Spool directory. Contains print jobs.
 /var/tmp : A place for temporary files which should be preserved between
system reboots.

21-05-2023 Side 57
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Shell
 A Shell provides an interface to the Unix system. It gathers input from user and
executes programs based on that input. When a program finishes executing, it
displays that program's output.
 Shell is an environment in which we can run our commands, programs, and shell
scripts. There are different flavors of a shell, just as there are different flavors of
operating systems. Each flavor of shell has its own set of recognized commands
and functions.
 The shell is the outermost layer of the operating system. Shells incorporate a
programming language to control processes and files, as well as to start and control
other programs.
Shell Types : In Unix, there are two major types of shells −
 Bourne shell − If you are using a Bourne-type shell, the $ character is the default
prompt.
 C shell − If you are using a C-type shell, the % character is the default prompt.
21-05-2023 Side 58
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Filters
Filters are programs that take plain text as standard input, transforms it into a
meaningful format, and then returns it as standard output. Linux has a number of
filters. Some of the most commonly used filters are explained below:
cat : Displays the text of the file line by line.
Syntax: cat [path]
head : Displays the first n lines of the specified text files.
Syntax: head [-number_of_lines_to_print] [path]
tail : It works the same way as head, just in reverse order. The only difference in
returns the lines from bottom to up.
Syntax: tail [-number_of_lines_to_print] [path]
sort : Sorts the lines alphabetically.
Syntax: sort [-options] [path]

21-05-2023 Side 59
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

uniq : Removes duplicate lines.


Syntax: uniq [options] [path]
wc : wc command gives the number of lines, words and characters in the data.
Syntax: wc [-options] [path]
grep : grep is used to search a particular information from a text file.
Syntax: grep [options] pattern [path]
tac : tac is just the reverse of cat and it works the same way.
Syntax: tac [path]
sed : sed stands for stream editor. It allows us to apply search and replace
operation on our data effectively.
Syntax: sed [path]
nl : nl is used to number the lines of our text data.
Syntax: nl [-options] [path]

21-05-2023 Side 60
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Shell Programming
A shell is special user program which provide an interface to user to use
operating system services. Shell accept human readable commands from user
and convert them into something which kernel can understand. It is a command
language interpreter that execute commands read from input devices such as
keyboards or from files. The shell gets started when the user logs in or start the
terminal.

21-05-2023 Side 61
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

 Shell is broadly classified into two categories –


1) Command Line Shell
2) Graphical shell
Command Line Shell
 Shell can be accessed by user using a command line interface. A special program
called Terminal in linux /mac OS or Command Prompt in Windows OS is
provided to type in the human readable commands such as “cat”, “ls” etc. and
then it is being execute. The result is then displayed on the terminal to the user.
Graphical Shells
Graphical shells provide means for manipulating programs based on graphical user
interface (GUI), by allowing for operations such as opening, closing, moving and
resizing windows, as well as switching focus between windows. Window OS or
Ubuntu OS can be considered as good example which provide GUI to user for
interacting with program.

21-05-2023 Side 62
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

Programming with the Standard I/O


An I/O system is required to take an application I/O request and send it to
the physical device, then take whatever response comes back from the
device and send it to the application. I/O devices can be divided into two
categories −
 Block devices − A block device is one with which the driver
communicates by sending entire blocks of data. For example, Hard disks,
USB cameras, Disk-On-Key etc.
 Character devices − A character device is one with which the driver
communicates by sending and receiving single characters (bytes, octets).
For example, serial ports, parallel ports, sounds cards etc

21-05-2023 Side 63
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

UNIX System Calls

 System calls in Unix are used for file system control, process control,
interprocess communication etc. Access to the Unix kernel is only
available through these system calls. Generally, system calls are similar to
function calls, the only difference is that they remove the control from the
user process.
 There are around 80 system calls in the Unix interface currently. Details
about some of the important ones are given as follows -

21-05-2023 Side 64
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
System Call Description
access() This checks if a calling process has access to the required file
chdir() The chdir command changes the current directory of the system
chmod() The mode of a file can be changed using this command
chown() This changes the ownership of a particular file
kill() This system call sends kill signal to one or more processes
link() A new file name is linked to an existing file using link system call.
open() This opens a file for the reading or writing process
pause() The pause call suspends a file until a particular signal occurs.
stime() This system call sets the correct time.
times() Gets the parent and child process times
alarm() The alarm system call sets the alarm clock of a process
fork() A new process is created using this command
chroot() This changes the root directory of a file.
21-05-2023 exit() The exit system call is used to exit a process. Side 65
Madan Mohan Malaviya Univ. of Technology, Gorakhpur

THE END

21-05-2023 Side 66

You might also like