0% found this document useful (0 votes)
32 views

Unit 1 To 4 - Linux

The document discusses file management concepts including what a file is, file attributes, file operations like creating, writing, reading, repositioning, deleting and truncating files. It also discusses file access methods including sequential and direct access.

Uploaded by

singal1006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Unit 1 To 4 - Linux

The document discusses file management concepts including what a file is, file attributes, file operations like creating, writing, reading, repositioning, deleting and truncating files. It also discusses file access methods including sequential and direct access.

Uploaded by

singal1006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS

MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR

Unit-1 File Management and Directory Management


Concept of File

Computers can store information on various storage media, such as magnetic disks, magneti
tapes, and optical disks. So that the computer system will be convenient to use, the operating
system provides a uniform logical view of information storage. The operating system abstracts
from the physical of its storage devices to define a logical storage unit, the file. Vites are
mapped by the operating system onto physical devices. These storage devices are nonvolatile,
so the contents are persistent through power failures and system reboots usually

A file is a named collection of related information that is recorded on secondary storagu: From
a bew's perspective, a file is the smallest allotment of logical secondary storage, that is, data
cannot bewrinen to secondary storage unless they are within a file. Commonly, files represent
programs thoth source and object forms) and data Data files may be numeric, alphabetic,
alphanumeric of Binary Files may be free form, such as text files, or may be formatted rigidly.
In general, a file is a sequence of bits, bytes, lines, or records, the meaning of which is defined
by the file's creator and user. The concept of a file is thus extremely general The information
in a file is defined by its creator. Many different types of information may be stored in a file-
source programs, object programs, executable programs, numeric data, text payroll records,
graphic images, sound recordings, and so on. A file has a certain defined which depends on its
type. A text file is a sequence of characters organized into lines (and possibly pages). A source
file is a sequence of subroutines and functions, each of which is further organized as
declarations followed by executable statements. An object file is a sequence of hytes organized
in to blocks understandable by the system's linker. An executable file is a series of code sections
that the loader can bring into memory and execute

File Attributes

t file is named, for the convenience of its human users, and is referred to by its name. A name
is usually a string of characters, such as example.e. Some systems differentiate between
uppercase and lowercase characters in names, whereas other systems do not. When a file is
named, it comes independent of the process, the user, and even the system that created it. For
instance, one user might create the file example.c, and another user might edit that file by
specifying its name. The file's owner might write the file to a floppy disk, send it in an e-mail,
or copy it across a network, and it could still be called example.c on the destination system. A
file's attributes vary from one operating system to another but typically consist of these:

Name

The symbolic file name is the only information kept in human readable form.

Identifier

This unique tag, usually a number, identifies the file within the file system the non-human-
readable name for the file.

Type

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 1


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
This information is needed for systems that support different types of files.

Location

This information is a pointer to a device and to the location of the file on that device.

Size

The current size of the file (in bytes, words, or blocks) and possibly the maximum allowed size
are included in this attribute. Protection. Access-control information determines who can do
reading, writing execiting, and so on.

Time, date, and user identification

This information may be kept for creation, last modification, and last use These data can be
useful for protection, security, and usage monitoring.

File Operations
A file is an abstract data type. To define a file properly, we need to consider the operatams that
can be performed on files. The operating system can provide system calls to create, write read
reposition, delete, and truncate files. Let's examine what the operating system must do to
perfons each of these six basic file operations. It should then be easy to see how other similar
operations such as renaming a file, can be implemented.

Creating a file

Two steps are necessary to create a file. First, space in the file system must be found for the
file. Second, an entry for the new file must be made in the directory.

Writing a file

To write a file, we make a system call specifying both the name of the file and the information
to be written to the file. Given the name of the file, the system searches the directory to find
the file's location.

The system must keep a write pointer to the location in the file where the next write is to take
place. The write pointer must be updated whenever a write occurs.

Reading a file

To read from a file, we use a system call that specifies the name of the file and where in
memory) the next block of the file should be put. Again, the directory is searched for the
associated entry, and the system needs to keep a read pointer to the location in the file where
the next read is to take place Once the read has taken place, the read pointer is updated. Because
a process is usually either reading from or writing to a file, the current operation location can
be kept as a per-process. Both the read and write operations use this same pointer, saving space
and reducing system complexity.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 2


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Repositioning within a file.

The directory is searched for the appropriate entry, and the current-file-position pomeris
repositioned to a given value. Repositioning within a file need not involve any actual 10 This
file operation is also known as a file seek.

Deleting a file

directTe delete file, we search the directory for the same file. Having found the cisted direction
entry we release all the space, as that it can be rensed by other files, and ethe directory enцу.

Truncating a file

The user may want to erase the contents of a file but keep its attributes. Rather than forcing the
user to delete the file and then recreate it, this function allows all attributes to remain unchanged
except for file length-but lets the file be reset to length zero and its file space released.

These six basic operations comprise the minimal set of required file operations. Other common
operations include appending new information to the end of an existing file and renaming an
existing file. These primitive operations can then be combined to perform other file operations.
For instance, we can create a copy of a file, or copy the file to another I/O device, such as a
printer or a display, by creating a new file and then reading from the old and writing to the new.
We also want to have operations that allow a user to get and set the various attributes of a file.
For example, we may want to have operations that allow a user to determine the status of a file,
such as the file's length, and to set file attributes, such as the file's owner.

File Access Method


Files store information. When it is used, this information must be accessed and read into
computer memory. The information in the file can be accessed in several ways. Some systems
provide only one access method for files. Other systems, such as those of IBM, support many
access methods. and choosing the right one for a particular application is a major design
problem.

1. Sequential Access

The simplest access method is sequential method. Information in the file is processed in order.
one record after the other. This mode of access is by far the most common; for example, editors
and compilers usually access files in this fashion.

Reads and writes make up the bulk of the operations on a file. A read operation-read next-reads
the next portion of the file and automatically advances a file pointer, which tracks the I/O
location. Similarly, the write operation-write next-appends to the end of the file and advances
to the end of the newly written material (the new end of file). Such a file can be reset to the
beginning, and on some systems, a program may be able to skip forward or backward n records
for some integer n-perhaps only for n= 1. Sequential access, which is depicted in Figure, is
based on a tape model of a file and works as well on sequential-access devices as it does on
random-access ones.

beginning Current position end

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 3


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Rewind read or write

A file is a made up of fixed length logical address that allow programs to read and write records
rapidly in no particular order. The direct-access method is based on a disk model of a file, since
disks allow random access to any file block. For direct access, the file is viewed as a numbered
sequence of blocks or records. Thus, we may read block 14, then read block 53, and then write
block 7. There are no restrictions on the order of reading or writing for a direct-access file.

2. Direct Access

Direct-access files are of great use for immediate access to large amounts of information.
Databases are often of this type. When a query concerning a particular subject arrives, we
compute which block contains the answer and then read that block directly to provide the
desired information. As a simple example, on an airline-reservation system, we might store all
the information about a particular flight (for example, flight 713) in the block identified by the
flight number. Thus, the number of available seats for flight 713 is stored in block 713 of the
reservation file. To store ill formation about a larger set such as people, we might compute a
hash function on the people's names or search a small in-ncemory index to determine a block
to read and search For the direct-access method, the file operations must be modified to include
the block number as a parameter. Thus, we have read n, where n is the block number, rather
than read next, and write n rather than write next. An alternative approach is to retain read next
and write next, as with sequential access, and to add an operation position file to n. where n is
the block number. Then, to effect a read n, we would position to n and then read next. The
block number by the user to the operating system is normally aA relative block number is an
index relative to the begirm.ing of the file. Thus, the first relative block of the file is 0, the next
is 1, and so on, even though the absolute disk address may be 14703 for the first block and
3192 for the second. The use of relative block numbers allows the operating system to decide
where the file should be placed (called the allocation problem, as discussed in Chapter 11) and
helps to prevent the user from accessing portions of the file system that may not be part of her
file. Some systems start their relative block numbers at 0; others start at 1. How, then, does the
system satisfy a request for record Nina file? Assuming we have a logical record length L., the
request for record N is turned into an 1/0 request for L bytes starting at location L (N) within
the file (assuming the first record is N = 0). Since logical records are of a fixed size, it is also
easy to read, write, or delete a record. Not all operating systems support both sequential and
direct access for files. Some systems allow only sequential file access, others allow only direct.

access. Some systems require that a file be defined as sequential or direct when it is created;
such a file can be accessed only in a manner consistent with its declaration. We can easily
simulate sequential access on a direct-access file by simply keeping a variable cp that defines
our current position, as shown in Figure. Simulating a direct-access file on a sequential-access
file, however, is extremely inefficient and clumsy.

Sequential access Implementation for direct access


Reset Cp=0;
Read next Read cp;
Cp=cp+1;

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 4


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Write next Write cp;
Cp=cp+1;

3. Indexed Sequential Method: (ISA)

Index Sequential access methods can be built on top of a direct-access method. These methods
generally involve the construction of an index for the file. The like an index in the back of a
contains pointers to the various blocks. To find a record in the file, we first search the index
and then use the to access the file directly and to find the desired record.

For example, a retail-price file might list the universal codes (UPCs) items, with the associated
prices. Each record consists a 10-digit UPC and a 6-digit price, a 16-byte record. If our disk
has 1.024 bytes per we can store 64 records per block. A file of 120,000 records would occupy
about 2.000 blocks (2 million bytes). By keeping the file sorted by UPC, we can define an
index consisting of the first UPC in each block. This index would have entries of 10 digits each,
or 20,000 bytes, and thus could be kept in memory. To find the price of a particular item, we
can make a binary search of the index. From this search, we learn exactly which block contains
the desired record and access that block. This structure allows us to search a large file doing
little 1/0. With large files, the index file itself may become too large to be kept in memory. One
solution is to create an index for the index file. The primary index file would contain pointers
to secondary index files, which would point to the actual data items. For example, IBM's
indexed sequential-access method (ISA) uses a small master index that points to disk blocks of
a secondary index. The secondary index blocks point to the actual file blocks. The file is kept
sorted on a defined key. To find a particular item, we first make a binary search of the master
index, which provides the block number of the secondary index. This block is read in, and
again a binary search is used to find the block containing the desired record. Finally, this block
is searched sequentially. In this way, any record can be located from its key by at most two
direct-access reads. Figure 10.5 shows a similar situation as implemented by VMS index and
relative files.

Adams
Arthur
Asher
.
.
.
smith

Directory Overview
The directory can be viewed as a symbol table that translates file names into their directory
entries. If we take such a view, we see that the directory itself can be organized in many ways.
We want to be able to insert entries, to delete entries, to search for a named entry, and to list
all the entries in the directory. In this

section, we examine several schemes for defining the logical structure of the directory system.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 5


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Directory Operation
Search for a fileWe need to be able to search a directory structure to find the entry for a
particular file. Since files have symbolic names, and similar names may indicate a relationship
between files, we may want to be able to find all files whose names match a particular pattern.

Create a file New files need to be created and added to the directory.

Delete a fileWhen a file is no longer needed, we want to be able to remove it from the directory.

List a directoryWe need to be able to list the files in a directory and the contents of the
directory en for each file in the list.

Rename a fileBecause the name of a file represents its contents to its users, we must be able
to change the name when the contents or use of the file changes. Renaming a file may also
allow its position within the directory structure to be changed.

Traverse the file systemWe may wish to access every directory and every file within a
directory structure. For reliability, it is a good idea to save the contents and structure of the
entire file system at regular intervals. Often, we do this by copying all files to magnetic tape.
This technique provides a backup copy in case of system failure. In addition, if a file is no
longer in use, the file can be copied to tape and the disk space of that file released for reuse by
another file.

Directory Structure
A directory is a container that is used to contain folders and file. It organized files and folders
into hierarchical manner. There are several logical structures of directory, these are given as
below.

1. Single level Directory Structure

Single level directory is simplest directory structure. In it all files are contained in same
directory which make it easy to support and understand.

A single level directory has a significant limitation, however, when the number of files
increases or when the system has more than one user. Since all the files are in the same
directory, they must have the unique name. if two users call their dataset test, then the unique
name rule violated.

Figure: Single level Directory Structure

Advantages:

Since it is a single directory, so its implementation is very easy. • If files are smaller in size,
searching will faster.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 6


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
The operations like file creation, searching, deletion, updating are very easy in such a directory
structure.

Disadvantages:

There may chance of name collision because two files cannot have the same name.

Searching will become time taking if directory will large.

In this cannot group the same type of files together.

2. Two level Directory Structure

As we have seen, a single level directory often leads to confusion of files names among
different users. the solution to this problem is to create a separate directory for each user.

In the two-level directory structure, each user has their own user files directory (UFD). The
UFDs has similar structures, but each lists only the files of a single user. system's master file
directory (MFD) is searches whenever a new user id=s logged in. The MFD is indexed by
username or account number, and each entry points to the UFD for that user.

Advantages:
We can give full path like /User-name/directory-name/.1040
Different users can have same directory as well as file name.
Searching of files become more easy due to path name and user-grouping.
Disadvantages:
A user is not allowed to share files with other users.
Still it not very scalable, two files of the same type cannot be grouped together in the same
user.
3.Tree Structured Directory Structure

Once we have seen a two-level directory as a tree of height 2, the natural generalization isto
extend the directory structure to a tree of arbitrary height. This generalization allows the user
to create their own subdirectories and to organized on their files accordingly.

Advantages:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 7


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Very generalize, since full path name can be given.

Very scalable, the probability of name collision is less.

Searching becomes very easy, we can use both absolute path as well as relative.

Disadvantages:

Every file does not fit into the hierarchical modelfiles may be saved into multipledirectories.

We cannot share files.

It is inefficient, because accessing a file may go under multiple directories.

Directory Implementation
The selection of directory-allocation and directory-management algorithms significantly
affects the efficiency, performance, and reliability of the file system. In this section, we
discuss the trade-offs involved in choosing one of these algorithms.

1. Linear List

The simplest method of implementing a directory is to use a linear list of file names with
pointers to the data blocks. This method is simple to program but time-consuming to execute.
To create a new file, we must first search the directory to be sure that no existing file has the
same name. Then, we add a new entry at the end of the directory. To delete a file, we search
the directory for the named file and then release the space allocated to it. To reuse the
directory entry, we can do one of several things. We can mark the entry as unused (by
assigning it a special name, such as an all-blank name, or with a used unused hit in each
entry), or we can attach it to a list of free directory entries. A third alternative is to copy the
last entry in the directory into the freed location and to decrease the length of the directory. A
linked list can also be used to decrease the time required to delete a file

The real disadvantage of a linear list of directory entries is that finding a file requires a linear
search. Directory information is used frequently, and users will notice if access to it is slow.
In fact, many operating systems implement a software cache to store the most recently used
directory information. A cache hit avoids the need to constantly reread the information from
CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 8
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
disk. A sorted list allows a binary search and decreases the average search time. However, the
requirement that the list be kept sorted may complicate creating and deleting files, since we
may have to move substantial amounts of directory information to maintain a sorted
directory. A more sophisticated tree data structure, such as a B-Tree, might help here. An
advantage of the sorted list is that a sorted director listing can be produced without a separate
sort step.

2. Hash Table

Another data structure used for a file directory is Hash Table with this method, a linear list
stores the directory entries, but a hash data structure is also used. The hash table takes a value
computed from the file name and returnsa pointer to the file name in the linear list. Therefore,
it can greatly decrease the directory search time. Insertion and deletion are also fairly
straightforward, although some provision must be made for collisions-situations in which two
file names hash to the same location.

The major difficulties with a hash table are its generally fixed size and the dependence of the
hash function onthat size. For example, assume that we make a linear-probing hash table that
holds 64 entries. The hash functionconverts file names into integers from 0 to 63, for instance,
by using the remainder of a division by 64. If welater try to create a 65th file, we must enlarge
the directory hash table-say, to 128 entries. As a result, we need anew hash function that must
map file names to the range 0 to 127, and we must reorganize the existing directoryentries to
reflect their new hash-function values.

alternatively, a chained-overflow hash table can be used. Each hash entry can be a linked list
instead of an individual value, and we can resolveble and Each has entry can be linked
Lookups may be somewhat slowed, because searching for a name might require steppinary to
the linked list of colliding table entries. Still, this method is likely to be much faster than a
linear search through the entire directory.

Disk Space Allocation Method

The allocation methods define how the files are stored in the disk blocks. There are three
main file allocation methods.

• Contiguous Allocation
• Linked Allocation
• Indexed Allocation

The main idea behind these methods is to provide:

• Efficient disk space utilization.


• Fast access to the file blocks.

All the three methods have their own advantages and disadvantages as discussed below:

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

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 9


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
to the file will be: b, b+1, b+2........btn-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.

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.

Advantages:

Both the Sequential and Direct Accesses are supported by this. For direct access, the
address of the kth block of the file which starts at block b can easily be obtained as (b-k).
This is extremely fast since the number of seeks are minimal because of contiguous allocation
of file blocks.

Disadvantages:

This method suffers from both internal and external fragmentation. This makes it
inefficient in terms of memory utilization, Increasing file size is difficult because it depends
on the availability of contiguous memory at a particular instance.

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

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 10


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR

Advantages:

This is very flexible in terms of file size. File size can be increased easily since the system
does not have to look for a contiguous chunk of memory. This method does not suffer from
external fragmentation. This makes it relatively better in in terms of memory utilization.

Disadvantages:

Because the file blocks are distributed randomly on the disk, a large number of seeks are
needed to access every block individually. This makes linked allocation slower.

It does not support random or direct access. We cannot directly access the blocks of a file. A
block k of a file can be accessed by traversing k blocks sequentially (sequential access) from
the starting block of the file via block pointers.

Pointers required in the linked allocation incur some extra overhead.

3. 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:

Advantages:

This supports direct access to the blocks occupied by the file and therefore provides fast
access to the file blocks.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 11


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
It overcomes the problem of external fragmentation.

Disadvantages:

The pointer overhead for indexed allocation is greater than linked allocation.

For very small files, say files that expand only 2-3 blocks, the indexed allocation would keep
one entire block (index block) for the pointers which is inefficient in terms of memory
utilization. However, in linked allocation we lose the space of only I pointer per block.

Free Space Management


The system keeps tracks of the free disk blocks for allocating space to files when they are
created. Also, to reuse the space released from deleting the files, free space management
becomes crucial. The system maintains

a free space list which keeps track of the disk blocks that are not allocated to some file or
directory. The free space list can be implemented mainly as:

1. Bitmap or Bit vector –

A Bitmap or Bit Vector is series or collection of bits where each bit corresponds to a disk
block. The bit can take two values: 0 and 1: 0 indicates that the block is allocated and I
indicates a free block. The given instance of disk blocks on the disk in Figure 1 (where green
blocks are allocated) can be represented by a bitmap of 16 bits as: 0000111000000110.

Advantages –

Simple to understand.

Finding the first free block is efficient. It requires scanning the words (a group of 8 bits) in a
bitmap for a non-zero word. (A 0-valued word has all bits 0).

The first free block is then found by scanning for the first 1 bit in the non-zero word.

The block number can be calculated as: (number of bits per word) *(number of 0-values
words) + offset of bit first bit I in the non-zero word.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 12


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
we scan the bitmap sequentially for the first non-zero word.The first group of 8 bits
(00001110) constitute a non-zero word since all bits are not 0. After the non-0 word is found,
we look for the first 1 bit. This is the 5th bit of the non-zero word. So, offset = 5. Therefore,
the first free block number = 8*0+5 = 5.

2.linked list-

In this approach,the free disk blocks are linked together i.e, a free black contains a pointer to
the next free block.the block number of the very first disk block is stored at a seprate location
on disk and is also cached in memory.

3.grouping-

This approach stores the address of the free blocks in the first free block. The first free block
stores the address of some,say n free blocks.out of these n blocks, the first n-1 blocks are
actually free and the last block contains the address of next free n block.

An advantage of this approach is that the addresses of a group of free disk blocks can be
found easily.

4.Counting-

This approach stores the address of the first free disk block and a number n of free contiguous
disk blocks that follow the first block.

Every entry in the list would contain:

1.address of first free disk block

2. a number n

For example in figure the first entry of the free space list would be([address of block
5],2),because 2 contiguous free blocks follow block 5.

Unit 2 i/o management


Typical pc bus structure

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 13


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
i/o devices can be roughly categorized as storage,communications,user-interface and other.

Devices communicate with the computer via signals sent over wires or through the air.

Devices connect with the computer viaparts,e.g. a serial or parallel part .

A common set of wires connecting multiple devices is termed a bus.

Buses include rigid protocols for the types of messages that can be sent across the bus and the
procedures for resoving contention issues.

Figure below illustrates three of the four bus types commonly found in a morden pc.

1.thepci bus connects high-speed high-bandwidth devices to the memory subsystem(and the
cpu).

2.the expansion bus connects a lower low-bandwidth devices,which typically deliver data one
character at a time(with buffering).

3.thescsi bus connects a number of scsi (small compuer system interface)devices to a common
SCSI controller.

4.A daisy-chain bus,(not shown) is when a string of devices is connected to each other like
beads on a chain, and only one of the devices is directly connected to the host.

One way of communicating with devices is through registers associated with each port.

Registers may be one to four bytes in size. And may typically include (a subset of) the following
four:

The data in register is read by the host to get input from the device.

The data-out register is written by the host to send output.

The status register has bits read by the host to determine the status of the device,such as idele,
ready for input ,busy,error,transaction complete etc.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 14


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
The control register has bits written by the host to issue commands or to change settings of the
device such as parity checking, word lengthor full versus half-duplex operation.

Another technique for communicating with devices is memory-mapped i/o

In this case a certain portion of the processor’s address space is mapped to the device,and
communicates occur by reading and writing directly to from those memory areas.

Memory-mapped i/o can be used either instead of or more often in combination with traditional
register .for example graphics cards still use register for control information such as setting the
video mode.

A potential problem exiss with memory-mapped i/o ,if a processs is allowed to write directly
to the address space used by a memory –mapped i/o device.

Polling:

the complete protocol for interaction between the host and a controller can be complex, but the
basic handshaking notion is simple.

Handshaking is explained with an example.

Assume that 2 bits are used to coordinate the producer-consumer relationship between the
controller and the host.the controller indicates its state through the busy bit in the status register.

The controller sets the busy bit when it is busy working and clears the busy bit when it is ready
to accept the next command.

The host signals its wishes via the command-ready bit in the command register.the host sets
the command-ready bit when a command is available for the controller to execute.

One simple means of device handshaking involves polling:

1.the host repeatedly checks the busy bit on the device until it becomes clear.

2. the host writes a byte of data into the data-out register,and sets the write bit in the command
register.

3. the host sets the command ready bit in the command ready bit set,it first sets the busy bit.

4.when the device controller sees the command ready bit set,it first sets the busy bit.

5. then the device controller reads the command register ,sees the write bit set,reads the bytes
of data from the data-out register and outputs the byte of data.

6.the device controller then clears the error bit in the status register ,the command-ready bit,and
finally clears the busy bit,signaling the completion of the operation

Polling can be very fast and efficient ,if both the device and the controller are fast and if there
is significant data to trtansfer.it becomes inefficient,however.if the host must wait a long time
in the busy loop waiting for the device,or if frequent cheeks need to be made for data that is
infrequently there.

Interrupts:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 15


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
interrupts allow devices to notify the cpu when they have data to transfer or when an operation
is complete,allowing the cpu to perform other sduties when no i/o transfers need its immediate
attention.

The cpu has an interrupt-request line that is sensed after every instruction.

A device’s controller raises an interrupt by asserting a signal on the interrupt request line.

The cpu then performs c state save and transfers control to the interrupt,performs the nessary
processing ,performs a state restore, and executes a return from intrupts introduction.

What is a DMA Controller?

Direct Memory Access uses hardware for accessing the memory, that hardware is called a
DMA Controller. It has the work of transferring the data between Input Output devices and
main memory with very less interaction with the processor. The direct Memory Access
Controller is a control unit, which has the work of transferring data.

DMA Controller Diagram in Computer Architecture:

DMA Controller is a type of control unit that works as an interface for the data bus and the I/O
Devices. As mentioned, DMA Controller has the work of transferring the data without the
intervention of the processors, processors can control the data transfer. DMA Controller also
contains an address unit, which generates the address and selects an I/O device for the transfer
of data. Here we are showing the block diagram of the DMA Controller.

Types of Direct Memory Access (DMA)


There are four popular types of DMA.
Single-Ended DMA
Dual-Ended DMA
Arbitrated-Ended DMA
Interleaved DMA
Single-Ended DMA: Single-Ended DMA Controllers operate by reading and writing
from a single memory address. They are the simplest DMA.

Dual-Ended DMA: Dual-Ended DMA controllers can read and write from two memory
addresses. Dual-ended DMA is more advanced than single-ended DMA.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 16


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Arbitrated-Ended DMA: Arbitrated-Ended DMA works by reading and writing to
several memory addresses. It is more advanced than Dual-Ended DMA.

Interleaved DMA: Interleaved DMA are those DMA that read from one memory
address and write from another memory address.

Working of DMA Controller

The DMA controller registers have three registers as follows.

Address register – It contains the address to specify the desired location in memory.

Word count register – It contains the number of words to be transferred.

Control register – It specifies the transfer mode.

Note: All registers in the DMA appear to the CPU as I/O interface registers. Therefore,
the CPU can both read and write into the DMA registers under program control via the data
bus.

The figure below shows the block diagram of the DMA controller. The unit
communicates with the CPU through the data bus and control lines. Through the use of the
address bus and allowing the DMA and RS register to select inputs, the register within the
DMA is chosen by the CPU. RD and WR are two-way inputs. When BG (bus grant) input is 0,
the CPU can communicate with DMA registers. When BG (bus grant) input is 1, the CPU has
relinquished the buses and DMA can communicate directly with the memory.

Explanation: The CPU initializes the DMA by sending the given information through
the data bus.
• The starting address of the memory block where the data is available (to read) or where
data are to be stored (to write).
• It also sends word count which is the number of words in the memory block to be read or
written.
• Control to define the mode of transfer such as read or write.
• A control to begin the DMA transfer
Modes of Data Transfer in DMA
There are 3 modes of data transfer in DMA that are described below.
• Burst Mode: In Burst Mode, buses are handed over to the CPU by the DMA if the
whole data is completely transferred, not before that.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 17


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
• Cycle Stealing Mode: In Cycle Stealing Mode, buses are handed over to the CPU by
the DMA after the transfer of each byte. Continuous request for bus control is generated
by this Data Transfer Mode. It works more easily for higher-priority tasks.
• Transparent Mode: Transparent Mode in DMA does not require any bus in the transfer
of the data as it works when the CPU is executing the transaction.
8237 DMA Controller
8237 DMA Controller is a type of DMA Controller which has a flexible number of channels
but generally works on 4 Input-Output channels. In these present channels, the channel has
to be given the highest priority to be decided by the Priority Encoder. Each channel in the
8237 DMA Controller has to be programmed separately.
8257 DMA Controller
8257 DMA Controller is a type of DMA Controller, that when a single Intel 8212 I/O device
is paired with it, becomes 4 channel DMA Controller. In 8257 DMA Controller, the highest
priority channel is acknowledged. It contains two 16-bit registers, one is DMA Address
Register and the other one is Terminal Count Register.
Advantages of DMA Controller
• Data Memory Access speeds up memory operations and data transfer.
• CPU is not involved while transferring data.
• DMA requires very few clock cycles while transferring data.
• DMA distributes workload very appropriately.
• DMA helps the CPU in decreasing its load.
Disadvantages of DMA Controller
• Direct Memory Access is a costly operation because of additional operations.
• DMA suffers from Cache-Coherence Problems.
• DMA Controller increases the overall cost of the system.
• DMA Controller increases the complexity of the software.

Kernel I/O Subsystem in Operating System

The kernel provides many services related to I/O. Several services such as scheduling,
caching, spooling, device reservation, and error handling – are provided by the kernel’s I/O
subsystem built on the hardware and device-driver infrastructure. The I/O subsystem is also
responsible for protecting itself from errant processes and malicious users.
1. I/O Scheduling –
To schedule a set of I/O requests means to determine a good order in which to execute
them. The order in which the application issues the system call is the best choice.
Scheduling can improve the overall performance of the system, can share device access
permission fairly to all the processes, and reduce the average waiting time, response
time, and turnaround time for I/O to complete.
OS developers implement schedules by maintaining a wait queue of the request for each
device. When an application issues a blocking I/O system call, The request is placed in
the queue for that device. The I/O scheduler rearranges the order to improve the efficiency
of the system.

2. Buffering –
A buffer is a memory area that stores data being transferred between two devices or
between a device and an application. Buffering is done for three reasons.
1. The first is to cope with a speed mismatch between the producer and consumer of a
data stream.
2. The second use of buffering is to provide adaptation for data that have different data-
transfer sizes.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 18


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
3. The third use of buffering is to support copy semantics for the application I/O, “copy
semantic ” means, suppose that an application wants to write data on a disk that is
stored in its buffer. it calls the write() system’s call, providing a pointer to the buffer
and the integer specifying the number of bytes to write.

3. Caching –
A cache is a region of fast memory that holds a copy of data. Access to the cached copy
is much easier than the original file. For instance, the instruction of the currently running
process is stored on the disk, cached in physical memory, and copied again in the CPU’s
secondary and primary cache.
The main difference between a buffer and a cache is that a buffer may hold only the
existing copy of a data item, while a cache, by definition, holds a copy on faster storage
of an item that resides elsewhere.

4. SpoolingandDeviceReservation –
A spool is a buffer that holds the output of a device, such as a printer that cannot accept
interleaved data streams. Although a printer can serve only one job at a time, several
applications may wish to print their output concurrently, without having their output mixes
together.
The OS solves this problem by preventing all output from continuing to the printer. The
output of all applications is spooled in a separate disk file. When an application finishes
printing then the spooling system queues the corresponding spool file for output to the
printer.

5. ErrorHandling –
An Os that uses protected memory can guard against many kinds of hardware and
application errors so that a complete system failure is not the usual result of each minor
mechanical glitch, Devices, and I/O transfers can fail in many ways, either for transient
reasons, as when a network becomes overloaded or for permanent reasons, as when a disk
controller becomes defective.

6. I/O Protection –
Errors and the issue of protection are closely related. A user process may attempt to issue
illegal I/O instructions to disrupt the normal function of a system. We can use the various
mechanisms to ensure that such disruption cannot take place in the system.
To prevent illegal I/O access, we define all I/O instructions to be privileged instructions.
The user cannot issue I/O instruction directly.
The Kernel I/O Subsystem in Operating System
An Operating System (OS) is a complex software program that manages the hardware and
software resources of a computer system. One of the critical components of an OS is the
Kernel I/O Subsystem, which provides an interface between the operating system and
input/output (I/O) devices. The Kernel I/O Subsystem manages the I/O requests made by the
user applications and translates them into hardware commands that the devices can
understand. In this article, we will discuss the importance of the Kernel I/O Subsystem and
its advantages and disadvantages.
Importance of Kernel I/O Subsystem
The Kernel I/O Subsystem is an essential part of any modern Operating System. It provides
a unified and consistent interface to the I/O devices, which enables the user applications to
access them without knowing the details of the underlying hardware. The Kernel I/O
Subsystem also manages the concurrency and synchronization issues that arise when
multiple applications try to access the same device simultaneously.
Advantages of Kernel I/O Subsystem
• Device Independence: The Kernel I/O Subsystem provides device independence to the
user applications. It abstracts the hardware details and provides a unified interface to the
CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 19
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
devices. This means that the application developers can write code that is independent of
the hardware platform, and the Kernel I/O Subsystem takes care of the hardware-specific
details.
• Efficient Resource Management: The Kernel I/O Subsystem provides efficient
resource management for the I/O devices. It manages the I/O requests and schedules them
in a way that optimizes the usage of the available resources. This ensures that the I/O
devices are not overutilized, and the system remains responsive.
• Concurrency Management: The Kernel I/O Subsystem manages the concurrency
issues that arise when multiple applications try to access the same device simultaneously.
It ensures that the applications get exclusive access to the device when needed and allows
multiple applications to share the device when appropriate.
Disadvantages of Kernel I/O Subsystem
• Complex Implementation: The Kernel I/O Subsystem is a complex software
component that requires a lot of resources to implement and maintain. Any issues with the
Kernel I/O Subsystem can affect the performance and stability of the entire system.
• Security Risks: The Kernel I/O Subsystem can pose security risks to the system if not
implemented correctly. Attackers can exploit vulnerabilities in the Kernel I/O Subsystem
to gain unauthorized access to the system or cause a denial-of-service attack.
Typical functions and services offered by the Kernel:

1. Process management: Save context of the interrupted program, dispatch a process,


manipulate scheduling lists.
2. Process communication: Send and receive interprocess messages.
3. Memory management: Set memory protection information, swap-in/ swap-out, handle
page fault.
4. I/O management: Initiate I/O ,process I/O completion interrupt, recover from I/O errors.
5. File management: Open a file, read/ write data.
6. Security and protection: Add authentication information for a new user, maintain
information for file protection.
7. Network management: Send/ receive data through a message.
Disk Scheduling Algorithms in OS (Operating System)

As we know, a process needs two type of time, CPU time and IO time. For I/O, it requests the
Operating system to access the disk.

However, the operating system must be fare enough to satisfy each request and at the same
time, operating system must maintain the efficiency and speed of process execution.

The technique that operating system uses to determine the request which is to be satisfied next
is called disk scheduling.

Let's discuss some important terms related to disk scheduling.

Seek Time

Seek time is the time taken in locating the disk arm to a specified track where the read/write
request will be satisfied.

Rotational Latency

It is the time taken by the desired sector to rotate itself to the position from where it can access
the R/W heads.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 20


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Transfer Time

It is the time taken to transfer the data.

Disk Access Time

Disk access time is given as,

Disk Access Time = Rotational Latency + Seek Time + Transfer Time

Disk Response Time

It is the average of time spent by each request waiting for the IO operation.

Purpose of Disk Scheduling

The main purpose of disk scheduling algorithm is to select a disk request from the queue of IO
requests and decide the schedule when this request will be processed.

Disk Scheduling Algorithms

The list of various disks scheduling algorithm is given below. Each algorithm is carrying some
advantages and disadvantages. The limitation of each algorithm leads to the evolution of a new
algorithm.

o FCFS scheduling algorithm


o SSTF (shortest seek time first) algorithm
o SCAN scheduling
o C-SCAN scheduling
o LOOK Scheduling
o C-LOOK scheduling

What is FCFS Disk Scheduling algorithm?

FCFS stands for First-Come-First-Serve. It is a very easy algorithm among the all-disk
scheduling algorithms. It is an OS disk scheduling algorithm that runs the queued requests and
processes in the way that they arrive in the disk queue. It is a very easy and simple CPU
scheduling algorithm. In this scheduling algorithm, the process which requests the processor
first receives the processor allocation first. It is managed with a FIFO queue.

Example:

Let's take a disk with 180 tracks (0-179) and the disk queue having input/output requests in the
following order: 81, 110, 38, 156, 68, 172, 92, 10. The initial head position of the Read/Write
head is 45. Find the total number of track movements of the Read/Write head using the FCFS
algorithm.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 21


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR

Total head movements,

The initial head point is 45,

(81-45) + (110-81) + (110-38) + (156-110) + (156-68) + (172-156) + (172-92) + (92-10)

= 36 + 29 + 72 + 46 + 88 + 16 + 80 + 82

= 449

Advantages

1. It is the very easy type of disk scheduling algorithm.


2. It is easy to use.
3. It provides first come first served process.
4. In FCFS, each process eventually has a chance to execute, therefore there is no
starvation.

Disadvantages

1. It is not very efficient because of its simplicity.


2. Its average waiting time is high.
3. It is a Non-Preemptive CPU Scheduling Algorithm, which implies that once a process
has been assigned to a CPU, it would never release the CPU until the process has
completed executing.

What is SSTF Disk Scheduling Algorithm?

SSTF stands for Shortest Seek Time First, and it serves the request that is closest to the
current position of the head. The direction of the head pointer is quite important in this
algorithm. When a tie happens between requests, the head will serve the request in its current
direction. In comparison to the FCFS, the SSTF algorithm is very efficient in terms of the total
seek time.

Example:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 22


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Let's take an example to understand the SSTF Disk Scheduling Algorithm. Let's take a disk
with 180 tracks (0-179) and the disk queue having input/output requests in the following
order: 87, 110, 50, 172, 67, 156, 39, 15. The initial head position of the Read/Write head is 45
and will move in the left-hand side direction. Find the total number of track movements of the
Read/Write head using the SSTF algorithm.

Solution:

Total head movements,

Initial head point is 45,

= (50-45) + (50-39) + (39-15) + (67-15) + (87-67) + (110-87) + (156-110) + (172-156)

= 5 + 11 + 14 + 52 + 20 + 23 + 46 + 16

= 187

Advantages and Disadvantages of SSTF Disk Scheduling Algorithm

There are various advantages and disadvantages of SSTF Disk Scheduling Algorithm. These
advantages and disadvantages are as follows:

Advantages
1. It improves and increase the throughput.
2. SSTF's total seek time is lower than the FCFS.
3. It has less response time and average waiting time.

Disadvantages
1. Starvation can happen for requests far from the head.
2. In the SSTF disk scheduling algorithm, the high variance is available in waiting time
and response time.
3. The algorithm is slowed by frequent changes in the head's direction.

FCFS Disk Scheduling Algorithm SSTF Disk Scheduling Algorithm

FCFS stands for First Come First Serve. SSTF stands for Shortest Seek Time First.

It is not effective in seek movements. It is very effective in seek movements.

It increases the total seek time than the SSTF. It reduces the total seek time than the FCFS.

It gives more response time and average waiting It gives less response time and average
time. waiting time.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 23


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
It doesn't cause starvation to any request. The request which is far from the head will
suffer starvation in the SSTF algorithm.

Its head direction doesn't matter, and the head Its head direction plays an important role in
moves in both forward or reversed directions. breaking a tie between requests.

What is SCAN Disk Scheduling Algorithm?

It is also known as the Elevator algorithm. In this algorithm, the head may move in both
directions, i.e., the disk arm begins to move from one end of the disk to the other end and
servicing all requests until it reaches the other end of the disk. After reaching the other end, the
head position direction is changed and further continues servicing the requests till the end of
the disk.

Example:

Let's take a disk with 180 tracks (0-179) and the disk queue having input/output requests in the
following order: 75, 90, 40, 135, 50, 170, 65, 10. The initial head position of the Read/Write
head is 45 and will move on the left-hand side. Find the total number of track movements of
the Read/Write head using the SCAN algorithm.

Solution:

Total head movements,

Initial head point is 45,

= (45-40) + (40-10) + (10-0) + (50-0) + (65-50) + (75-65) + (90-75) + (135-90) + (170-135)

= 5 + 30 +10 +50 +15 + 10 +15 + 45 + 35

= 215

Advantages and Disadvantages of SCAN Disk Scheduling Algorithm

There are various advantages and disadvantages of SCAN disk scheduling algorithm. These
advantages and disadvantages are as follows:

Advantages

1. In the SCAN disk scheduling algorithm, low variance happens in the waiting time and
response time.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 24


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2. The starvation is avoided in this disk scheduling algorithm.

Disadvantages

1. If no requests remain to be serviced, the head moves till the end of the disk.

What is C-SCAN Disk Scheduling Algorithm?

It is also known as the Circular Elevator algorithm. It is an improved version of the SCAN
disk scheduling algorithm. In this algorithm, the head works for requests in a single direction,
i.e., it scans all the way to the end of a direction and then jumps to another end and services the
requests in the same direction.

Example:

Let's take a disk with 180 tracks (0-179) and the disk queue having input/output requests in the
following order: 75, 90, 40, 135, 50, 170, 65, 10. The initial head position of the Read/Write
head is 45 and will move on the right-hand side. Find the total number of track movements of
the Read/Write head using the C-SCAN algorithm.

Solution:

Total head movements,

The initial head point is 45,

= (50-45) + (65-50) + (75-65) + (90-75) + (135-90) + (170-135) + (179-170) + (179-0) + (10-


0) + (40-10)

= 5 + 15 + 10 +15 + 45 + 35 + 9 +179 + 10 + 30

= 353

Advantages and Disadvantages of C-SCAN Disk Scheduling Algorithm

There are various advantages and disadvantages of the C-SCAN disk scheduling algorithm.
These advantages and disadvantages are as follows:

Advantages

1. It gives a uniform waiting time.


2. It gives a better response time.
3. The head travels from one end to the other disks end and serves all requests along the
way.
CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 25
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
4. The C-SCAN algorithm is the improved version of the SCAN scheduling algorithm.

Disadvantages

1. If no requests remain to be serviced, the head will travel to the end of the disk.
2. It generates more search movements than the SCAN algorithm.

What is the LOOK Disk Scheduling Algorithm?

It is the more advanced version of the SCAN disk scheduling algorithm. In this algorithm, the
head begins at one end of the disk and works its way to the other end, and serving all requests
along the way. When the head reaches the end of one end's last request, it changes direction
and returns to the first request, servicing all requests in between. Unlike SCAN, instead of
going to the last track, this head goes to the last request and then changes direction.

Example:

Let's take an example to understand the LOOK Disk Scheduling Algorithm. Let's take a disk
with 180 tracks (0-179) and the disk queue having input/output requests in the following
order: 75, 90, 40, 135, 50, 170, 65, 10. The initial head position of the Read/Write head is 45
and would move on the right-hand side. Find the total number of track movements of the
Read/Write head using the LOOK disk scheduling algorithm.

Solution:

Total head movements,

The initial head point is 45,

= (50-45) + (65-50) + (75-65) + (90-75) + (135-90) + (170-135) + (170-40) + (40-10)

= 5 + 15 + 10 + 15 + 45 + 35 + 130 + 30

= 285

Advantages and Disadvantages of LOOK Disk Scheduling Algorithm

There are various advantages and disadvantages of the LOOK Disk Scheduling Algorithm.
These advantages and disadvantages are as follows:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 26


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Advantages

1. It provides better performance in comparison to the SCAN algorithm.


2. The LOOK scheduling algorithm avoids starvation.
3. The head will not move to the end of the disk if no more requests are fulfilled.
4. Waiting time and response time have a low variance.

Disadvantages

1. There is an overhead of finding the final requests.

C-LOOK Disk Scheduling Algorithm

It is a combination of the LOOK and SCAN disk scheduling algorithms. In this disk scheduling
algorithm, the head begins from the initial request to the last request in the other direction and
serves all requests in between. The head jumps in the other direction after finishing the last
request at one end and proceeds towards the remaining requests, completing them in the same
direction as previously. Unlike LOOK, it only responds to requests in one direction.

Example:

Let's take an example to understand the C-LOOK Disk Scheduling Algorithm. Let's take a
disk with 180 tracks (0-179) and the disk queue having input/output requests in the following
order: 75, 90, 40, 135, 50, 170, 65, 10. The initial head position of the Read/Write head is 45
and would move on the right-hand side. Find the total number of track movements of the
Read/Write head using the C-LOOK disk scheduling algorithm.

Solution:

Total head movements,

The initial head point is 45,

= (50-45) + (65-50) + (75-65) + (90-75) + (135-90) + (170-135) + (170-10) + (40-10)

= 5 + 15 + 10 + 15 + 45 + 35 + 160 + 30

= 315

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 27


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Advantages and Disadvantages of C-LOOK Disk Scheduling Algorithm

There are various advantages and disadvantages of the C-LOOK Disk Scheduling Algorithm.
These advantages and disadvantages are as follows:

Advantages

1. It provides better performance compared to the LOOK disk scheduling algorithm.


2. The starvation is avoided in the C-LOOK disk scheduling algorithm.
3. If no requests are to be served, the head doesn't have to go all the way to the end of the
disk in the C-LOOK disk scheduling algorithm.
4. In C-LOOK, there is minimal waiting time for cylinders that are only visited by the
head.
5. Waiting time and response time have a low variance.

Disadvantages

1. The overhead of finding the end requests is present in C-LOOK.

Unit 3Introduction to Unix and Linux Operating System (Open


Source)
Introduction to UNIX System
Unix is an Operating System that is truly the base of all Operating Systems like Ubuntu,
Solaris, POSIX, etc. It was developed in the 1970s by Ken Thompson, Dennis Ritchie, and

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 28


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
others in the AT&T Laboratories. It was originally meant for programmers developing
software rather than non-programmers.
Unix and the C were found by AT&T and distributed to government and academic
institutions, which led to both being ported to a wider variety of machine families than any
other operating system. The main focus that was brought by the developers in this operating
system was the Kernel. Unix was considered to be the heart of the operating System. The
system Structure of Unix OS are as follows:
UNIX is a family of multitasking, multiuser computer operating systems developed in the
mid 1960s at Bell Labs. It was originally developed for mini computers and has since been
ported to various hardware platforms. UNIX has a reputation for stability, security, and
scalability, making it a popular choice for enterprise-level computing.
The basic design philosophy of UNIX is to provide simple, powerful tools that can be
combined to perform complex tasks. It features a command-line interface that allows users
to interact with the system through a series of commands, rather than through a graphical
user interface (GUI).
Some of the key features of UNIX include:
1. Multiuser support: UNIX allows multiple users to simultaneously access the same
system and share resources.
2. Multitasking: UNIX is capable of running multiple processes at the same time.
3. Shell scripting: UNIX provides a powerful scripting language that allows users to
automate tasks.
4. Security: UNIX has a robust security model that includes file permissions, user
accounts, and network security features.
5. Portability: UNIX can run on a wide variety of hardware platforms, from small
embedded systems to large mainframe computers.
Today, UNIX is widely used in enterprise-level computing, scientific research, and web
servers. Many modern operating systems, including Linux and macOS, are based on UNIX
or its variants.
• Layer-1: Hardware: It consists of all hardware related information.
• Layer-2: Kernel: It interacts with hardware and most of the tasks like memory
management, task scheduling, and management are done by the kernel.
• Layer-3: Shell commands: Shell is the utility that processes your requests. When you
type in a command at the terminal, the shell interprets the command and calls the program
that you want. There are various commands like cp, mv, cat, grep, id, wc, nroff, a.out and
more.
• Layer-4: Application Layer: It is the outermost layer that executes the given external
applications.

Figure – kernel and its block diagram


This diagram shows three levels: user, kernel, and hardware.

• The system call and library interface represent the border between user programs and the
kernel. System calls look like ordinary function calls in C programs. Assembly language

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 29


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
programs may invoke system calls directly without a system call library. The libraries are
linked with the programs at compile time.
• The set of system calls into those that interact with the file subsystem and some system
calls interact with the process control subsystem. The file subsystem manages files,
allocating file space, administering free space, controlling access to files, and retrieving
data for users.
• Processes interact with the file subsystem via a specific set of system calls, such as open
(to open a file for reading or writing), close, read, write, stat (query the attributes of a file),
chown (change the record of who owns the file), and chmod (change the access
permissions of a file).
• The file subsystem accesses file data using a buffering mechanism that regulates data
flow between the kernel and secondary storage devices. The buffering mechanism
interacts with block I/O device drivers to initiate data transfer to and from the kernel.
• Device drivers are the kernel modules that control the operator of peripheral devices.
The file subsystem also interacts directly with “raw” I/O device drivers without the
intervention of the buffering mechanism. Finally, the hardware control is responsible for
handling interrupts and for communicating with the machine. Devices such as disks or
terminals may interrupt the CPU while a process is executing. If so, the kernel may resume
execution of the interrupted process after servicing the interrupt.
• Interrupts are not serviced by special processes but by special functions in the kernel,
called in the context of the currently running process.
Difference between Unix and Linux
Linux is essentially a clone of Unix. But, basic differences are shown below:
Linux Unix

The source code of Linux is freely The source code of Unix is not freely
available to its users available general public

It has graphical user interface along with


It only has command line interface
command line interface

Linux OS is portable, flexible, and can be


Unix OS is not portable
executed in different hard drives

Different versions of Linux OS are


Different version of Unix are AIS, HP-
Ubuntu, Linux Mint, RedHat Enterprise
UX, BSD, Iris, etc.
Linux, Solaris, etc.

The file systems supported by Linux are as


The file systems supported by Unix are as
follows: xfs, ramfs, vfat, cramfsm, ext3,
follows: zfs, js, hfx, gps, xfs, vxfs
ext4, ext2, ext1, ufs, autofs, devpts, ntfs

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 30


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Linux Unix

Linux is an open-source operating system Unix is a proprietary operating system that


that was first released in 1991 by Linus was originally developed by AT&T Bell
Torvalds. Labs in the mid 1960s.

The Unix kernel is modular, meaning that


The Linux kernel is monolithic, meaning
it is made up of a collection of independent
that all of its services are provided by a
modules that can be loaded and unloaded
single kernel.
dynamically.

Unix was originally designed to run on


Linux has much broader hardware support large, expensive mainframe computers,
than Unix. while Linux was designed to run on
commodity hardware like PCs and servers.

User Interface of Linux is Graphical or


User Interface of unix is text-based.
text-based.

Command Line Interface of Linux is Bash, Command Line Interface of unix is


Zsh, Tcsh. Bourne, Korn, C, Zsh.

Advantages of UNIX:
1. Stability: UNIX is known for its stability and reliability. It can run for long periods of
time without requiring a reboot, which makes it ideal for critical systems that need to run
continuously.
2. Security: UNIX has a robust security model that includes file permissions, user
accounts, and network security features. This makes it a popular choice for systems that
require high levels of security.
3. Scalability: UNIX can be scaled up to handle large workloads and can be used on a
variety of hardware platforms.
4. Flexibility: UNIX is highly customizable and can be configured to suit a wide range of
needs. It can be used for everything from simple desktop systems to complex server
environments.
5. Command-line interface: UNIX’s command-line interface allows for powerful and
efficient interaction with the system.
Disadvantages of UNIX:
1. Complexity: UNIX can be complex and difficult to learn for users who are used to
graphical user interfaces (GUIs).
2. Cost: Some UNIX systems can be expensive, especially when compared to open-source
alternatives like Linux.
3. Lack of standardization: There are many different versions of UNIX, which can make it
difficult to ensure compatibility between different systems.
4. Limited software availability: Some specialized software may not be available for UNIX
systems.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 31


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
5. Steep learning curve: UNIX requires a certain level of technical knowledge and
expertise, which can make it challenging for novice users.
Linux system call in Detail
A system call is a procedure that provides the interface between a process and the operating
system. It is the way by which a computer program requests a service from the kernel of the
operating system.
Different operating systems execute different system calls.
In Linux, making a system call involves transferring control from unprivileged user mode to
privileged kernel mode; the details of this transfer vary from architecture to architecture. The
libraries take care of collecting the system-call arguments and, if necessary, arranging those
arguments in the special form necessary to make the system call.
System calls are divided into 5 categories mainly :
• Process Control
• File Management
• Device Management
• Information Maintenance
• Communication

Process Control :
This system calls perform the task of process creation, process termination, etc.
The Linux System calls under this are fork() , exit() , exec().
• fork()
• A new process is created by the fork() system call.
• A new process may be created with fork() without a new program being run-
the new sub-process simply continues to execute exactly the same program that
the first (parent) process was running.
• It is one of the most widely used system calls under process management.
• exit()
• The exit() system call is used by a program to terminate its execution.
• The operating system reclaims resources that were used by the process after the
exit() system call.
• exec()
• A new program will start executing after a call to exec()
• Running a new program does not require that a new process be created first:
any process may call exec() at any time. The currently running program is
immediately terminated, and the new program starts executing in the context of
the existing process.
File Management :
File management system calls handle file manipulation jobs like creating a file, reading, and
writing, etc. The Linux System calls under this are open(), read(), write(), close().
• open():
• It is the system call to open a file.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 32


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
• This system call just opens the file, to perform operations such as read and
write, we need to execute different system call to perform the operations.
• read():
• This system call opens the file in reading mode
• We can not edit the files with this system call.
• Multiple processes can execute the read() system call on the same file
simultaneously.
• write():
• This system call opens the file in writing mode
• We can edit the files with this system call.
• Multiple processes can not execute the write() system call on the same file
simultaneously.
• close():
• This system call closes the opened file.
Device Management :
Device management does the job of device manipulation like reading from device buffers,
writing into device buffers, etc. The Linux System calls under this is ioctl().
• ioctl():
• ioctl() is referred to as Input and Output Control.
• ioctl is a system call for device-specific input/output operations and other
operations which cannot be expressed by regular system calls.
Information Maintenance:
It handles information and its transfer between the OS and the user program. In addition, OS
keeps the information about all its processes and system calls are used to access this
information. The System calls under this are getpid(), alarm(), sleep().
• getpid():
• getpid stands for Get the Process ID.
• The getpid() function shall return the process ID of the calling process.
• The getpid() function shall always be successful and no return value is reserved
to indicate an error.
• alarm():
• This system call sets an alarm clock for the delivery of a signal that when it has
to be reached.
• It arranges for a signal to be delivered to the calling process.
• sleep():
• This System call suspends the execution of the currently running process for
some interval of time
• Meanwhile, during this interval, another process is given chance to execute
Communication :
These types of system calls are specially used for inter-process communications.
Two models are used for inter-process communication
1. Message Passing(processes exchange messages with one another)
2. Shared memory(processes share memory region to communicate)
The system calls under this are pipe() , shmget() ,mmap().
• pipe():
• The pipe() system call is used to communicate between different Linux
processes.
• It is mainly used for inter-process communication.
• The pipe() system function is used to open file descriptors.
• shmget():
• shmget stands for shared memory segment.
• It is mainly used for Shared memory communication.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 33


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
• This system call is used to access the shared memory and access the messages
in order to communicate with the process.
• mmap():
• This function call is used to map or unmap files or devices into memory.
• The mmap() system call is responsible for mapping the content of the file to the
virtual memory space of the process.

UNIX is no longer a small system, it is a rather very powerful one. Unlike Windows & DOS,
UNIX can be used concurrently by several users. You can interact with a UNIX system through
a command-line interpreter called the shell. UNIX is a computer operating system that was
first developed on 3 November 1971 and has been constantly updated since then.

Features of UNIX

Unix is an operating system, so it has all the features that the OS must-have. UNIX also looks
at a few things in a different way than other OS. Features of UNIX are listed below :
1. Multiuser System :
Unix provides multiple programs to run and compete for the attention of the CPU. This happens
in 2 ways :
• Multiple users running multiple jobs
• Single user running multiple jobs
In UNIX, resources are actually shared between all the users, so-called a multi-user system.
For doing so, computer give a time slice (breaking unit of time into several segments ) to each
user. So, at any instant of time, only one user is served but the switching is so fast that it gives
an illusion that all the users are served simultaneously.
2. Multitask System :
A single user may run multiple tasks concurrently. Example : Editing a file, printing another
on the printer & sending email to a person, and browsing the net too at the same time. The
Kernel is designed to handle user’s multiple needs.
The important thing here is that only one job can be seen running in the foreground, the rest all
seems to run in the background. Users can switch between them, terminate/suspend any of the
jobs.

3. The Building-Block Approach :


The Unix developers thought about keeping small commands for every kind of work. So Unix
has so many commands, each of which performs one simple job only. You can use 2 commands
by using pipes (‘|’). Example : $ ls | wc Here, | (pipe) connects 2 commands to create a pipeline.
This command counts the number of files in the directory. These types of connected commands
that can filter/manipulate data in other ways are called filters.
Nowadays, many UNIX tools are designed in a way that the output of 1 can be used as an input
for the others.. We can create a large number of combinations by connecting a number of tools.
4. The UNIX Toolkit :
Unix has a kernel but the kernel alone can’t do much that could help the user. So, we need to
use the host of applications that usually come along with the UNIX systems. The applications
are quite diversified. General-purpose tools, text manipulation utilities (called filters),
compilers and interpreters, networked programs, and system administration tools are all
included. With every UNIX release, new tools are being added and the older ones are modified/
removed.
5. Pattern Matching :

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 34


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Unix provides very sophisticated pattern matching features. The meta-char ‘*’ is a special
character used by the system to match a number of file names. There are several other meta-
char in UNIX. The matching is not confined to only filename. Advanced tools use a regular
expression that is framed with the characters from this set.
6. Programming Facility :
Unix provides shell which is also a programming language designed for programmers, not for
casual end-users. It has all the control structures, loops, and variables required for programming
purposes. These features are used to design the shell scripts ( programs that can invoke the
UNIX commands).
Many functions of the system can be controlled and managed by these shell scripts.
7. Documentation :
It has a ‘man’ command that stands for the manual, which is the most important reference for
any commands and their configuration files. Apart from the offline documentation, there is a
vast amount of resources available on the Internet. If you’re stuck with a problem, there are
various UNIX newsgroups where you can post your concerns. You can also go through the
FAQ(Frequently Asked Questions) – a document that addresses several problems is widely
used & available on the Net.
8. Portable:
Unix is highly portable, meaning it can be easily adapted to run on different hardware
architectures.
9. Command-line interface:
Unix has a powerful command-line interface (CLI) that allows users to interact with the system
through a shell program.
10. File system:
Unix has a hierarchical file system, with all files and directories organized under a single root
directory.
11. Networking:
Unix was designed from the ground up to support networking, making it an ideal choice for
servers and other networked systems.
12. Security:
Unix has robust security features built-in, including user-level permissions and access control
lists.
13. Open-source:
Many versions of Unix are open-source, meaning that the source code is freely available for
users to modify and distribute.
14. Scalability:
Unix is highly scalable, allowing it to be used on everything from small embedded systems to
large-scale data centers.
Application area of Linux Operating System
Following are application areas of Linux operating system.

1. Revive an Old or Slow PC

We come to one of the most obvious and common uses for Linux.If you have a PC that's seen
better days, Windows is far from the ideal OS.

Install a lightweight Linux distribution on it and it'll feel like a newmachine again.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 35


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2. Brush Up on Your Hacking and Security

Some Linux distributions, like BackTrack or Kali, are security-focuseddistros for testing
security systems.

3. Create a Dedicated Media Center or Video Game Machine:

XBMC works great on Linux, whether you're running on a RaspberryPi or just a low-powered
PC, and you can turn just about any PC intoan all-in-one retro video game console.

4. Run a Home Server for Backup, Streaming, Torrenting, and More

If you don't want to leave your computer on 24/7 just to share files ordownload torrents, a tiny
dedicated Linux box might be a bettersolution. With an old computer or a cheap new one, you
can puttogether a home server that stores your backups, streams movies andmusics, seeds
torrents, or performs any number of other tasks quietly inthe corner.

5. Automate Everything In Your Home

With a little Linux knowledge and a cheap computer—like theRaspberry Pi— you can create
all sorts of tiny home automationgadgets. You can control your home with Siri, mount a
GoogleCalendar tablet on your wall, set up a home surveillance system,control your blinds and
air conditioner, stream music in your livingroom, build a digital photo frame, build a sunrise
alarm clock,and...pretty much anything else you can think of.

6. Work with Hard Drives and Partitions

If you dual- or triple-boot your system and ever want to movepartitions around, you'll have a
much easier time with a Linux live CDand GParted.

7. Host a Web Site or Webapp

You'd be surprised how many web sites you visit every day actuallyrun on Linux—and if you
want to build a web site, you probably willtoo.

8. Troubleshoot Other Computers

You don't even need to install Linux on a box to make it useful—all you need is asolid live
CD. Just boot from the CD and you can grab any files from the hard drive,even if the computer
won't boot or you've forgotten your password.

Various Linux Flavors

Describe different flavors of Linux OS. OR Explain about popular Linux flavors.Linux is not
just a single operating system. It exists in several dozenversions called distributions.

Unlike Windows, no one company has guided the developmentof Linux. Some Linux
distributions are developed on userfriendlystandards.

Two main shell architectures are used by most of all distribution, known asGNOME and KDE.

Linux software is distributed in packages, mostly by download.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 36


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Debian:

• Debian is regarded as the largest Linux distribution to date interms of users. It is famous for
its stability and quality.

• It has a very large numbers of users and over 28,000 packages youcan add to it. It is very
stable and newbie friendly.

Ubuntu:

• The most popular distorts out in the world right now, since its releasefive years ago.

• Some suggest it has as much as 40% of Linux desktops. It is anothergood quality, stable
release that is very newbie friendly.

• It even has a migration assistant for Windows refugees.

• This eases the pain a little by helping you in your first steps.

Fedora:

• This is a distribution with a long history. Once part of Red Hat, Fedorawas launched for the
‘Linux Hobbyist’.

• It is very secure and has a large number of packages available for it.

• This one seemed to be less newbie friendly than others, with not somany options for desktop
users.

• If you want to run a web server or something then this would be ideal.

• Current version is Fedora 10, new version shortly.

OpenSUSE:

• This is another distros with a rich history, now owned by Novell.

• It is a comprehensive package with some good documentation.

• The following is helpful and informative and there are lots of packagesavailable for it.

• There is however some controversy over a deal it has with Microsoft,something about use of
patents.

• This doesn’t detract from the usability of the product though.

• It does have graphical tools for an administrator. Current release is

11.1.Mandriva:

• Mandriva used to be Mandrake, and even as a Windows user back thenI knew what that was.

• It is one of the distributions that offer both free and commercialversions of the software.

• The commercial version is regarded as one of the best distros fornewbies.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 37


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
• Although I don’t see that it has much that Ubuntu or Debian doesn’toffer and for free.

• Current version is Mandriva 2009.1.

Slackware:

• This is allegedly the oldest Linux distribution still around today.

• It is supposed to be the cleanest and most bug free edition available, butseems quite hard core.

• You definitely need skills to get into Slackware.

• It lags a little behind other distributions and doesn’t have all the coolbits to make your desktop
smart.

• Current version 12.2.

Mint:

• It is based on Ubuntu, but is developed mainly ‘on demand’.

• The programmers have forums and feedback loops which theysubscribe to.

• They listen and try to implement the best suggestions into thedistribution.

• It has many specific tools, and to my mind is the most useable out ofthe box.

• Current version is Mint 6 Felicia.

Desktop Environment: (a) X Window Basic (b) KDE Basic (c) GNOME Basic

Write a short note on X Window system. OR Describe about X Window system.

What is X window:

The X window system is a computer software and network protocol thatprovides a basis for
graphical user interfaces (GUIs) and input devicecapability for networked computers.

It creates a hardware layer where software is written to use a generalizedset of commands.

X originated at the Massachusetts Institute of Technology (MIT) in 1984.

The X.Org Foundation leads the X project, with the current referenceimplementation,

Xorg Server, available as free and open source software under the MITLicense and similar
permissive licenses.

Functions of X Window:

X windows allows many people to share the processing power of a timesharingcomputer.Each


person using a networked terminal has the ability to interact withthe display with any type of
user input device.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 38


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
X is commonly used to run client applications on personal computers.

It is provides the basic framework for building such GUIenvironments.X window was
specifically designed to be used over network connections.It is often used in conjunction with
an X session manager toimplement sessions.

The X Protocol:

The X protocol was developed in the mid-1980s to provide anetwork transparent graphical user
interface (GUI).

The X protocol organizes display operations into a client and serverrelationship.

The client is known as an X client and the server as an X serverX client can send requests to
have an X server on a local machineperform certain display operations.

Several-client systems access a single server.Xorg Configuration: /etc/X11/xorg.confThe Xorg


servers provide a wide range of hardware support, but it can bechallenging to configure.

The configuration file used for your Xorg server is called xorg.conf,located in the /etc/X11
directory.xorg.conf contains all the specifications for your graphics card,monitor, keyboard,
and mouse.

To configure the xorg.conf file, you need specific information on handabout your
hardware.You can use anXorg configuration utility built into the Xorg server.You can use the
Xorg command with the -configure option.

Limitations of X window:

✓ User interface issues

o The lack of design guidelines in X has resulted in severaldifferent interfaces, and in


applications that have not alwaysworked well together.

✓ Computer accessibility related issues

o Systems built upon the X windowing system may haveaccessibility by disabled users

✓ Network

o An X client cannot generally be detached from one serverand reattached to another unless its
code specificallyprovides for it.

✓ Client–server separation

o X's design requires the clients and server to operate separately.

✓ Competitors

o Some people have attempted writing alternatives to andreplacements for X.

What is GNOME:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 39


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
GNOME is a desktop environment and graphical user interface.GNOME was started in August
1997 by Miguel de Icaza and Federico Mena. Inplace of Qt, the GTK+ toolkit was chosen as
the base of GNOME.

GNOME itself is licensed under the GNU General Public License (GPL) for itsapplications.

The GNU Network Object Model Environment is full form of GNOME,You can download the
source code of GNOME software directly fromgnome.org.Several companies have joined
together to form the GNOME Foundation,These include such companies as Sun, IBM, and
Hewlett- Packard as well asLinux distributors such as Fedora, SUSE, and TurboLinux.

Features of GNOME:

It is requires less time to load and use less memory.Gedit has been word editor program for
Multiple Document.F-Spot image is a camera managers and the Beagle is a search tool.The
new menu editor-Alacarte, lets you customize your menus easily.The disk usage analyzer,
Baobab, lets you quickly see how much diskspace is used.

The GNOME video player-Totem, supports web access, featuringWindows Media Player
support.

Buttons and windows are easier to use and appear more pleasing to the eye.

The Cairo images theme is compliant with the TANGO style guidelines.

GNOME provides the Seahorse Encryption Key Manager forencryption, signing, and
decryption of files and text.

The GNOME Control Center provides an organization and access for yourdesktop
configuration.

GNOME Interface:

The GNOME interface consists of the panel and a desktop, as shownin following figure.The
panel appears as a long bar across the bottom of the screen.It holds menus, programs, and
applets.The menu operates like the Start menu and lists entries for applicationsyou can run on
your desktop.

You can display panels horizontally or vertically and have themautomatically hide to show you
a full screen.The Applications menu is reserved for applications. Other tasks, such asopening
a home directory window or logging out, are located in the Placesmenu.

The System menu holds the Preferences menu for configuring yourGNOME interface, as well
as the Administration menu for accessing thedistribution administrative tools.

GNOME Components:

The GNOME interface as having four components:

thedesktop,the panels,

the main menus, and

the file manager.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 40


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
The desktop displays a Computer window for accessing the entirefile system.

You have two panels displayed, one used for menus, application icons, andrunning applets at
the top of the screen, and one at the bottom of the screen usedprimarily for managing your
windows and desktop spaces.

To the right are the time and date icons. An update button will appear if updatesare available.

Explain about GNOME packages and management.

GNOME Packages and Management:

The packages are separated into “Platform” and “Desktop” sections in thesame manner as the
sources are distributed on the GNOME.

Packages:

Platform Packages:

GIO Files:

GIO provides APIs for asynchronously reading and writing filesand other streams.

Files are referenced by URIs.

When running under the GNOME desktop, GIO uses SFTP,

FTP, WebDAV, SMB, and other popular protocols.

This transparent network file access is free to all applications usingGIO.

GIO Networking:

GIO provides high-level networking APIs to communicate over

TCP/IP and UNIX domain sockets.

You can use the GIO networking APIs to connect to a server,

listen for events, and read resources.

The asynchronous API designs means your application doesn'tblock waiting for a response.

GStreamer:

GStreamer is a powerful multimedia library for playing, creating,and manipulating sound,


video, and other media.

You can use GStreamer to provide sound and video playback,record input from multiple
sources, and edit multimedia content.`

GStreamer supports encoding and decoding numerous formats bydefault, and support for
additional formats can be added with plug-ins.

WebKit:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 41


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
WebKit is a powerful, multi-platform HTML engine used inopen source and commercial
products.

WebKitGTK+ makes it easy to add web functionality to yourapplication, or to use HTML5 and
associated technologies tocreate dynamic user interfaces quickly.

Desktop Packages:

Brasero:

Brasero is a simple application to burn, copy and erase CDand DVD media: audio, video or
data.

This package contains the main binary, the burning plugins and thenautilus extension.

Cheese:

Cheese is a cheesy program to take pictures and videos fromyour web cam. It also provides
some graphical effects in order toplease the user's play instinct.

Deskbar-applet:

Deskbar-applet is intended as a browser-like keyword-driven url bar.You type a web address,


or an email address, or a file name, orsome keyword then the arguments, and it shows a popup
with possiblechoices from there.

Management:

Installing software in GNOMEIn the Search Box with the magnifying glass icon, type the name
of the

application you wish to install.Next, click the Find button – The message Querying appears in
the lowerleft corner briefly and then zero or more listings will appear that matchyour search
query.Tick the box next to the description of the application you wish to install.

Select any additional packages to install or remove at this time bychanging tick boxes next to
the package name.Finally, click the Apply button. This starts the installation process.

Unless an error is displayed, the application is now installed (or removed)on your computer.

Removing software in GNOME

To remove software you should follow the standard installation procedure,but untick boxes
beside the programs you wish to uninstall.

Click System - Administration - Add/Remove Software. This will openthe Add/Remove


Software application.

In the Search Box with the magnifying glass icon, type the name of theapplication you wish to
remove.

Next, click the Find button. The message Querying appears in the lowerleft corner briefly then
zero or more listings will appear that match yoursearch query.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 42


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Untick the box next to the description of the application you wish toremove.

Finally, click the Apply button.

Unless an error is displayed, the application is now removed from your computer.

Write a short note on KDE. OR explain about KDE.

Introduction to KDE:

KDE is an international free software community producing an integratedset of applications


designed to run on Linux, FreeBSD, MicrosoftWindows, Solaris and Mac OS X systems.

The goal of the community is to provide basic desktop functions andapplications.

KDE software is based on the Qt framework. KDE was founded in 1996 byMatthias Ettrich.

He proposed the creation of not merely a set of applications but a desktopenvironment in which
users could expect things to look, feel, and workconsistently.

He also wanted to make this desktop easy to use, the KDE project was born.

KDE Menus:

When you start KDE, the KDE panel is displayed at the bottom of the screen.The button for
the main menu shows a k, the KDE icon.

This is the button for the KDE main menu.Click this button to display the menu of applications
you run. (you canalso open the main menu by pressing ALT-F1).

KDE Windows

A KDE window has the same functionality you find in other windowmanagers and desktops.

You can resize the window by clicking and dragging any of its corners orsides.

You can perform click-and drag operation in the windowThe top of the window has a title bar
showing the name of the window,The active window has the title bar highlighted.

To move the window, click this title bar and drag it where you want.

You can configure the appearance and operation of a window.

Opened windows are also shown as buttons on the KDE taskbar located on thepanel.

KDE Panel: Kicker

The KDE panel (Kicker), located at the bottom of the screen, providesaccess to most KDE
functions.

The panel includes icons for menus, directory windows, specificprograms, and virtual
desktops.

At the left end of the panel is a button for the main menu (also known asthe K menu), a KDE
K icon.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 43


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
To add an application to the panel, right-click anywhere on the paneland select Add from the
pop-up menu.

KDE File Manager and Internet Client: KonquerorThe KDE file manager, known as
Konqueror, is a multifunctional utility with

which you can manage files, start programs, browse the web, and download filesfrom remote
sites.

Traditionally, the term “file manager” was used to refer to managing files onlocal hard disk.The
KDE file manager extends its functionality well beyond this traditionalfunction because it is
Internet capable, seamlessly displaying remote file systemsas if they were your own, as well
as viewing web pages with browsercapabilities.

It is capable of displaying a multitude of different kinds of files, including image,PostScript,


and text files.KOffice applications can be run within the Konqueror window. You can
evenopen a separate pane within a file manager window to run a terminal windowwhere you
can enter shell commands.

Licensing Issue of KDE:

The most common (and most commonly misunderstood) issue surrounding theKDE project is
the licensing issue.The combination of licenses between KDE and Qt make the issue lessthan
obvious, especially if you are using KDE/Qt to develop a closedsourceor commercial
application.These issues, for all their complexity, are manageable.

In some cases the KDE project uses a different license than the one thatTrolltech has chosen
for Qt.These licenses have different goals and purposes and apply to softwareprojects in
different ways.

The free version of Qt fell under the FreeQt license. This version wasavailable only if the
recipient's product was distributed under a freesoftware license. It permitted the redistribution
of Qt and access to thesource code.Explain the KDE Control Center. OR How to configure
KDE,With the KDE Control Center, you can configure your desktop andsystem. The Control
Center can be directly started by selecting ControlCenter from the main menu.The KDE
Control Center is the place to go to change any settings thataffect the whole of your KDE
environment.

The Control Center window is divided into two panes.The left pane shows a tree view of all
the components you can configure,and the right pane displays the dialog windows for the
selected component.The settings are divided into several major categories, which each
containseveral pages of settings.

✓ Appearance & Themes

Here you will find settings that change the way your KDEdesktop and applications look. For
example background, color,fonts, icon etc..

✓ Desktop

This is where you will find settings to configure the appearanceand behavior of your KDE
desktop. For example behavior,multiple desktop, panels, taskbar etc..
CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 44
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
✓ Internet & Network

This section is where you would configure settings to do withinternet and networking under
KDE. For example connectionpreferences, desktop sharing, file sharing, local
networkbrowsing etc..

✓ KDE Components

This section is where you can modify advanced KDE optionssuch as file associations and
default applications. For examplecomponent chooser, file manager, kde performance etc.

✓ Peripherals

This section is where you would change settings related toperipheral devices such as keyboards
and joysticks.

✓ Power Control

This section has a single module, Laptop Battery. Here you canconfigure the appearance and
behavior of the Klaptop daemonbattery monitor. You can select battery icons to
representdifferent power states, and set up notification of certain events.

✓ Regional & Accessibility

This section is where you can configure options to do with regionand locale, and also
accessibility related options for disabledpersons.

✓ KDE Wallet

o Here you can change your KDE Wallet Manager settings.

o KDE Wallet aims to provide secure storage for passwords andweb form data.

o The default wallet is named "kdewallet", and you can eithercreate a new wallet for your local
passwords or accept thedefault wallet for all data in the "Automatic Wallet Selection"section.

✓ Password & User Account

o You can change here your personal information which will beused in mail programs and
word processors.

✓ Privacy

o This module allows you to erase traces which KDE leaves onyour system such as command
histories or browser caches.

✓ System Administration

o This module allows you to configure aspects of your system suchas the bootloader, the kernel
and helps you perform essentialsystem tasks. Most of these sections will require the root
orAdministrator password to effect changes.

✓ Date & Time

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 45


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
o This configuration module allows you to configure the systemdate and time settings. You
can set the date, time, and also thecurrent time zone.

✓ Font Installer

o Here is where you would configure both personal and systemwidefonts. This dialog allows
you to install new fonts, delete oldones and preview the fonts you have installed.

✓ Linux Kernel

o If you run KDE on Linux there is a KControl module to create ormodify configuration files
for a Linux kernel. This configuratoris compatible with kernels previous to 2.5.

✓ Login Manager

o This module allows you to configure the KDE login manager,kdm. kdm is a powerful login
manager with a large range ofoptions.

Advantages and Disadvantages of Linux

Advantages:

Cost – The most clear advantage of using Linux is the fact that it is free to obtain,while
Microsoft products are available for a heavy and sometimes frequent fee.

Security –The security side of Linux is much stronger than that of windows. The
Linuxoperating system has managed to stay secure in the realm of widespread viruses,spyware
and adware for all these years.

Choice (Freedom) – The power of choice is a great Linux advantage. With Linux,you have the
power to control just about every aspect of the operating system.

Software - There are so many software choices when it comes to doing any specifictask.

Hardware - Linux is perfect for those old computers with barely any processing poweror
memory you have sitting in your garage or basement collecting dust.

No crashes- Windows users will be familiar with the infamous “blue screen of death”that greets
them whenever the system crashes. In contrast, Linux users have reporteduptimes exceeding
over a year, which means that their computers have beencontinuously running over a year
without a single crash or reboot.

Disadvantages:

Understanding – Becoming familiar with the Linux operating system requires patienceas well
as a strong learning habit.

Compatibility – Because of its free nature, Linux is sometimes behind the curve whenit comes
to brand new hardware compatibility. Though the kernel contributors andmaintainers work
hard at keeping the kernel up to date.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 46


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Alternative Programs – Though Linux developers have done a great job at creatingalternatives
to popular Windows applications, there are still some applications that existon Windows that
have no equivalent Linux application.

Different working mechanism - If you’re a lifelong Windows user, you may take awhile to get
used to the way Linux works. From installing software to runningprograms, things are a little
different in Linux-based systems.

Unit 4 Understanding File System Hierarchy Standard


What is file system? Explain about file system hierarchy standard.

“Files are arranged in proper way so user or system can access file easily is called File System”.

Different operating system manages these files in different way. All the files in your Linux
system are connected into one overall directory tree.Files on a particular storage device are
organized into what is referred to asa file system.

A file system is a formatted device, with its own tree of directories and files.Your Linux
directory tree may encompass several file systems, each ondifferent storage devices.

On a hard drive with several partitions, you have a file system for eachpartition.For example,
a floppy disk with Linux files has its own tree of directories.

File system Hierarchy Standard (FHS):

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 47


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
The organization and layout for the system directories are determined bythe file system
hierarchy standard (FHS).The FHS provides a standardized layout that all Linux distributions
shouldfollow insetting up their system directories.For example, there must be an /etc directory
to hold configuration files and a/dev directory for device files.

Linux distributions, developers, and administrators all follow the FHS toprovide a consistent
organization to the Linux file system.

You have access to these directories and files only as the systemadministrator..

Root Directory: /

The subdirectories held in the root directory, indicate by/ .Directories that you may commonly
access as an administrator are the /etcdirectory., which holds configuration files.

For managing different versions of the kernel, you may need to access the/boot and
/lib/modules directories as well as /usr/src/linux.

Directory Function

/ Begins the file system structure—called the root.

/boot Holds the kernel image files and associated boot information andfiles.

/home Contains users’ home directories.

System Directories

Your Linux directory tree contains certain directories whose files are usedfor different system
functions.

For basic system administration, you should be familiar with the systemprogram directories
where applications are kept, the system configurationdirectory (/etc) where most configuration
files are placed

Directory Description

/bin Holds system-related programs.

/sbin Holds system programs for specialized tasks.

/lib Holds system libraries.

Program Directories

Directories with bin in the name are used to hold programs.The /bin directory holds basic user
programs, such as login, shells and filecommands.

The /sbin directory holds specialized system programs for such tasks as filesystem
management.

Configuration Directories and Files

When you configure different elements of your system, configuration filesare placed in the /etc
directory.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 48


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
/usr Directory

The /usr directory contains a multitude of important subdirectories used tosupport users,
providing applications, libraries, and documentation.

/media Directory

The /media directory is used for mountpoints for removable media like CDROM,DVD, floppy,
or Zip drives etc..

/mnt Directory

The /mnt directory is usually used for mountpoints for other mounted filesystems such as
Windows partitions.

/home Directory

The /home directory holds user home directories. When a user account is setup, a home
directory is set up here for that account, usually with the samename as the user.

The /var Directory

The /var directory holds subdirectories for tasks whose files changefrequently, such as lock
files, log files, web server files, or printer spool files.How do you find out information about
file system in Linux?The file systems on each storage device are formatted to take up a
specifiedamount of space.

To find out how much space you have free on a filesystem, you can use the dfcommand or, on
the desktop, either the GNOME SystemMonitor or the KDEKDiskFree utility.

For the System Monitor, click the Resources tab todisplay a list of the freespace on your file
systems.

KDiskFree displays a list of devices,showing how much space is free on eachpartition, and the
percentage used.

Df :

The df command reports file system disk space usage. It lists all your filesystems by theirdevice
names, how much disk space they take up, and thepercentage of the disk spaceused, as well as
where they are mounted.

With the -h option, it displays information in amore readable formatThedf command is also a
safe way to obtain a listing of all your partitions.

$ df -h

File system Size Used Avail Use% Mounted on

Output:

/dev/hda3 9.7G 2.8G 6.4G 31% /

/dev/hda2 99M 6.3M 88M 7% /boot

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 49


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
You can also use df to tell you to what file system a given directory belongs.Enter dfwith the
directory name or df .for the current directory.

$ df .

Output:

File system 1024-blocks Used Available Capacity Mounted on

/dev/hda3 297635 169499 112764 60% /

e2fsck and fsck :

To check the consistency of the file system and repair it if it is damaged, youcan use filesystem
checking tools.

fsck checks and repairs a Linux file system. e2fsck is designed tosupport ext2and ext3 file
systems.

The ext2 and ext3 file systems are the file systems normally used forLinuxhard disk partitions
and floppy disks.Linux file systems are normally ext3, which you usee2fsck to check. fsck
ande2fsck take as their argument the device name of the hard diskpartition thatthe file system
uses.

fsck device-name

Before you check a file system, be sure that the file system is unmounted.

To use e2fsck, enter e2fsck and the device namethat references the filesystem.

The -p option automatically repairs a file system.The following examples check thedisk in the
floppy drive and the primaryhard drive:

# e2fsck /dev/fd0

# e2fsck /dev/hda1

With fsck, the -t option lets you specify the type of file system to check.

Directory Commands, File and Directory CommandsDescribe directory related commands.

(1) pwd(Print Working Directory):

Use : It is display current working directory.

Syn :pwd

Exam :pwd

(2) cd (Change Directory) :

Use : it is used to change directory.

Syn : cd <directory name > or <full path>

Exam :

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 50


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
(1) cd

It is change working directory to home directory

(2) cd..

It is change working directory to parent directory

(3) cd /user/lib

It is change working directory to absolute path /user/lib

(4) cd doc/letters

It is change working directory to relative path doc/lettes.

(3) rmdir (ReMoveDIRectory) :

Use : It is used to remove empty directory.

Exam :rmdir test

(4) mv (Move or Rename)

Use : it is used to rename a directory or move files from one directory toanother directory.

Syn : mv old_directoryNew_directory

Exam : mv abc test

Enlist the File related commands.

(1) cat (Create)

Use : This command is used to create, display and append content of a file.

Syn : cat [OPTION] [FILE]...

Example : cat >abc.dbf

(1) To create a file

Use : It is used to create a file.

Syn : cat > filename

Example : cat > man.mdb

(2) To display content of a file.

Use : It is used to display content of a file.

Syn : cat filename

Example : cat student.dbf

Options :

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 51


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
1) -n

Function : This option use to display lines of a file with line number.

Syntax : cat –n filename

Example : cat –n student.dbf

2) -e

Function : This option use to display $ sign at the end of each line of afile.

Syn : cat -$ filename

Example : cat -$ student.dbf

(3) To append content

Use : It is used to append new content into existing file.

Syn : cat >> filename

Example : cat >>student.dbf

(2) cp (Copy a file)

Use : It is used to copy a file from source to destination.

Syn :cp [option] sourcefiledestinationfile

Example :cp abc.txt abc.doc

Options :

1) –i

Function : This option will ask to user for overwrite or not by linux.

Syn :cp –i sourcefiledestinationfile

Example :cp -i abc.txt abc.doc

2) –r

Function : This option will copy directory recursively.

Syn :cp –r sourcefiledestinationfile

Example :cp –r /student/* /student/abc/

3) –s

Function : This option make symbolic links instead of copying

Syn :cp –s files

Example :cp –s hello.txt rajmitra.doc

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 52


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
4) –u

Function : This option copy source file/s only it is new.

Syn :cp –u sourcefiledestinationfile

(1) Example :cp –u hello.tct /abc/pqr/

(3) rm (remove) :

Use : it is delete a file.

Syn :rm –[option] file name

Exam :rm test.doc

Options :

(1) –i : interactive removal, ask before each removal.

(2) –r : recursive removal, perform recursive deletion in directory.

(3) –f : forceful removal, remove write protected file also.

(4) mv (Move or Rename)

Use : it is used to rename a file or move a file from one directory to anotherdirectory.

Syn : mv –[option] file1 file2/directory

Exam :

(1) mv abc.txt test.csh

It is rename abc.txt file to test.csh

(2) mv abc.txt archive/

It is move abc.txt file into directory archive

(5) ln (link)

Use : It is used to make hard link between different files.

Syn :ln [option] Target [link name]

Example :ln /abc hello.txt

Options :

1) –s : make symbolic links instead of hard links.

2) –b : make a backup of each existing destination file.

3) –f : remove existing destination file.

(6) ls (list)

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 53


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
(1) List files and directories.

Use :ls with no option list files and directories in bare format.

Syn :ls or ls [option]

Exa :ls

Options :

1) –l (long list)

Function : It shows file or directory, size, modified date and time, file or folder

name and owner of file and it’s permission.

Example :ls -l

2) –a (all)

Function: List all files including hidden file starting with ‘.‘.

Example :ls -a

3) –lh (long list with human reable format)

Function: With combination of -lh option, shows sizes in human readableformat.

Example :ls –lh

4) –F

Function: Using -F option with ls command, it will add the ‘/’ Character at theend each
directory, ‘*’ character at the end each executable file and‘@’ character at the end each
symbolic link.

Example: ls –F

5) –r (Reverse Order)

Function: This is option display files and directories in reverse order.

Example: ls –r

6)-R (Recursively list)

Function: These will list very long listing directory trees.

Example: ls -R

7) –S (Sort)

Function: This option displays file size in order, will display big in size first.

This option use with combination –l.

Example: ls –lS

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 54


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
8) –i (Inode number)

Function: This options list file / director+y with inode number.

Example :ls -i

9) --version

Function : Check version of ls command.

Example :ls --version

10) -n

Function : This options display UID and GID of files and directories.

Example: ls -n

(11) –color

Function : It is used to display list of directory and filed name with differentcolor.

Example :ls –color

(12) –t (time)

Function : This option display sorted list of all files and directory according todate and time.

Example :ls –t

(13) –X (extension)

Function : This option display sorted list of all files according to file extension.

Example :ls –X

2) List Directory Information

Use : This way of writing ls command display list files under specified directory.

Syn :ls –l /directory name

Example :ls -l /tmp

Note : You can press the tab key to auto complete the file or folder names.

3) List root directory.

Use : It is use to display root directory.

Syn :ls /

Exam :ls /

4) List parent directory

Use : To display parent directory.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 55


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Syn :ls ..

Exam :ls ..

5) List home directory

Use : It is display home directory of the user.

Syn :ls ~

Exam :ls ~

6) List only specified type of files

Use : It is display list of files of specified type.

Syn :ls *. file extension

Exam :ls *.doc

7) List directories only

Use : It is used to display only list of all the directory.

Syn :ls -d */

Exam :ls –d */

8) List files and directories with full path

Use : It is used to display all the files and subdirectory with full path.

Syn :ls -d $PWD/*

Exam :ls –d $pwd/*

(7) chmod (Change mode) :

Use : it is used to give permission to the files and directory.

Syn : There are two way to give permission (1) Character arguments (2) octalnotation.

(1) Character arguments :

Syn :chmod [ugoa] [+-=] [rwx] file name/directory.

Category: u – User, g – Group, o – Others, a – AllCategory Operations Permissions

Operations: + - assign, - - deny/set, = - absolute arguments.

Permissions: r – Read, w – Write, x – ExecutionExam :chmodu+rw abc.doc

(2) Numeric argument (Octal Notations)

Instead of the character arguments, we can give numeric arguments tothe “chmod” command.
The notation takes the form of an octalrepresentation of the permission and it is assign as follow
:

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 56


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Permissions Numeric Value

Read 4

Write 2

Execution 1

Total 7

Syn :chmod ### filename

Exam :chmod 761 xyz.txt

Here, 7 is used for user permission, 7 is total of4(read)+2(write)+1(execute) that means user
have all read, write andexecute permission. 6 is used for group permission, 6 is total of 4(read)
+2 (write) that means group have only read and write permission. 1 isused for other permission.
1 is total of 1(execute) means others have onlypermission of execution.

(8) wc (Word Count):

Use : It is used to count number of characters, words and lines in the given file.

Syn :wc –[option] file name

Exam: wc –l xyz.txt

Options :

(1) –l : counts number of lines

(2) –w : number of words

(3) –c : count number of characters.

(9) cmp (comparison)

Use : This command used to display input files are different or same. If both thefiles are same
it will not display message, otherwise it will display from whichcharacter and line it is deferred.

Syn :cmp file1 file2

Example :cmpprog.o.bakprog.o

Options :

1) –l

Function : This option is used to compares the files, and then displays thebyte number (in
decimal) and the differing bytes (in octal) for eachdifference.

Syn :cmp –l file1 file2

Example :cmp –l prog.o.bakprog.o

2) –s

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 57


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Function : This option compare two files but it will not display any messages.

Syn :cmp –s file1 file2

Example :cmp –s prog.o.bakprog.o

(10) diff (difference)

Use : This command is used to display two files and prints the lines that aredifferent.

Syn : diff [option] file1 file2

Example : diff abc.txt pqr.doc

Options :

1) –q

Function : This option is display message when two files are differedotherwise it will not
display any message.

Syn : diff –q file1 file2

Example : diff –q abc.txt pqr.doc

2) –s

Function : This option is display message when two files are same otherwise itwill not display
any message.

Syn : diff –s file1 file2

Example : diff –s abc.txt pqr.doc

3) –i

Function : This option is used to ignore case differences in file contents.

Syn : diff –i file1 file2

Example : diff –i abc.txt pqr.doc

(11) tty :

Use : It is used to display file name associated with terminal, remember thatall devices are
treated as file.

Syn :tty

(12) head

Use : This command is used to display specified lines of file/s.

Syn : head [option] file/s

Example : head abc.txt

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 58


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Options :

1) -c

Function : This option is used to print the first N bytes of file/s.

Syn : head –c n file/s

Example : head –c 5 abc.txt

2) –n

Function : This option is used to print first N lines of a file/s.

Syn : head –n N file/s.

Example : head –n 5 abc.txt

3) –q

Function : This option is used to display first N lines of file/s without headergiven in the file/s.

Syn : head –q file/s

Example: head –q abc.txt

4) –v

Function : This option is used to display first N lines of file/s with header given inthe file/s.

Syn : head –v file/s

Example: head –v abc.txt

(13) tail

Use : This command is used to display last lines of file/s.

Syn : tail [option] file/s

Example : tail abc.txt

Option:

1) -c

Function : This option is used to print the last N bytes of file/s.

Syn : head –c n file/s

Example : head –c 5 abc.txt

2) –n

Function : This option is used to print last N lines of a file/s.

Syn : head –n N file/s.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 59


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Example : head –n 5 abc.txt

3) –q

Function : This option is used to display last N lines of file/s without headergiven in the file/s.

Syn : head –q file/s

Example: head –q abc.txt

4) –v

Function : This option is used to display last N lines of file/s with header given inthe file/s.

Syn : head –v file/s

Example: head –v abc.txt

(14) cut :

Use : It is used to cut a file vertically, extract specific coloums or fields from aninput file.

Syn : cut –[option] list file name

Exam : cut –c 5-15, 20-25 test.txt

It is extract two coloums having characters –15 and 20-25

cut –f 2,3 test.txt

It is extract 2nd and 3rd coloum.

Options :

(1) –c : It is extract specific coloums as given in list.

(2) –f : it is extract specific fields as given in list.

(15) Paste:

Use : It is used to join content of files vertically. It will not add content of the file at

the end of the file.

Syn : paste [option] file/s

Example : paste abc.txt mno.doc pqr.xls

Options :

1) -s

Function : This option joins all the lines in a file. Since no delimiter is specified,default
delimiter tab is used to separate the columns.

Syn : paste –s abc.txt

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 60


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2) –d

Function : This is used to specify delimiter character.

Syn : paste –d char filename

Example : paste –d”*” pqr.doc

(1) Merge a file by pasting the data into 2 columns

Use : it is merge the lines of a file in two coloums instead of in a single line.

Syn : paste - - < filename

Example : paste - - < pqr.doc

(2) Merge a file by pasting the data into 2 columns using a colon separator

Use : It is merge the lines of a file in two coloums and separate the coloum by aspecified
character.

Syn : paste –d char - - < filename

Example :paste -d':' - - < Npq.doc

(16) sort

Use : This command is used to sort lines of text file. This command sort lines of afile by default
ascending order.

Syn : sort [option] file/s

Example : sort abc.txt pqr.doc

Options :

1) –b

Function : This option is used to ignore leading blanks.

Syn : sort –b file/s

Example : sort –b abc.txt pqr.doc

2) –f

Function : This option is used to ignore case.

Syn : sort –f file/s

Example : sort –f student.doc fees.txt

3) –n

Function : This option is used to sort the file according to numerical value.

Syn : sort –n file/s

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 61


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Example : sort –n fees.txt

4) –r

Function : This option is used to sort lines of files in reverse order.

Syn: sort –r file/s

Example : sort –r student.doc

5) –c

Function : This option is used to check that input file is sorted or not sorted.

Syn : sort –c file/s

Example : sort –c student.doc

6) –m list

Function : This option is used to merge sorted files in the list.

Syn : sort –m list file/s

Example : sort –m abc student.doc fees.dbf

7) –o

Function : This option is used to store sorted file/s in another file instead ofdisplay on standard
output.

Syn : sort –o file file/s

Example : sort –o abc.txt student.txt fees.doc

8) –t

Function : This option is used to make separate fields in the text file for sort.

Syn : sort –t char file/s

Example : sort –t”|” student.dbf

9) –u

Function: This option is used to remove duplicate lines of files for sorting.

Syn : sort –u file/s

Example : sort –u student.dbf

10) –k n

Function : This option is used sort a file on nth field.

Syn : sort –k n file/s

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 62


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Example : sort –k 3 student.dbf

11) –k m,n

Function : This option is used to start sort on mth field and end sort on nth field.

Syn : sort –k m,n file/s

Example : sort –k 3,6 student.dbf

12) –K m,n

Function: This option is used to start sort on nth coloum of mth field.

Syn sort –K m,n file/s

Example : sort –K 3,3 student.dbf

(17) tr (Translate)

Use : It is used to convert content of a file.

Syn :tr [option] “set1” “set2” < filename

Options :

(1) –c

Function : It will replace those characters in the input string which does notcontain in set1 with
the character define in set2.

Example :tr ‘[;alpha:] ‘d’ < abc.txt

(2) –s

Function : This option is used to replace of that character which repeated inthe input string and
contain that character in set1 with thecharacter define in set2.

Example :tr –s ‘\n’ ‘ ’ < filename

(1) [:lower:] [:upper:]

Function : It is used to display content of a file from lower case into upper case.

Syn :tr [:lower:] [:upper:] < file name

Or

tr ‘[a-z]’ ‘[A-Z]’ < file name

Or

tr a-z A-Z< file name

Exam :tr [:lower:] [:upper:] < abc.txt

Or

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 63


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
tr ‘[a-z]’ ‘[A-Z]’ < abc.txt

Or

tr a-z A-Z< abc.txt

(18) grep

Use : This command is used to find (search) a pattern in file/s.

Syn :grep [options] pattern file/s

Example :grep “hello” letter.txt

Options :

1) –i

Function: This option is used to ignore case while it is search specified pattern.

Syn :grep -i pattern file/s

Example :grep -i "UNix" file.txt

2) –w

Function : This option is used to search whole pattern in a file instead of part ofthe pattern.

Syn :grep -w pattern file/s

Example :grep -w "UNix" file.txt

3) –B

Function : This option is used to display n lines before match the pattern line.

Syn :grep –B n pattern file/s

Example :grep –B 2 “Error” log.txt

4) –A

Function : This option is used to display n lines after match the pattern line.

Syn :grep –A n pattern file/s

Example :grep –A 2 “Error” log.txt

5) -C

Function : This option is used to display n lines before and after match thepattern line.

Syn :grep –C n pattern file/s

Example :grep –C 2 “Error” log.txt

6) –r

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 64


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Function : This option is used to search a string in all the files of currentdirectory and sub
directory.

Syn :grep –r pattern file/s

Example :grep –r “string” *

7) –v

Function : This option is used to display the lines that are not matched with thespecified search
sting pattern.

Syn :grep –v pattern file/s

Example :grep -v "string" file.txt

8) –c

Function : This option is used to count number of lines that match the specifiedunderstring
pattern.

Syn :grep –c pattern file/s

Example :grep –c “rajesh” student.txt

9) –l

Funtion : This option is used to display only those file name which contain thelines match the
specified pattern.

Syn :grep –l pattern file/s

10) –o

Function : This option is used to display on match pattern instead of displaywhole line that
contain specified pattern.

Syn :grep –o pattern file/s

Example :grep –o “right” student.txt

11) –n

Function : This option is used to display line with line number which match thespecified
pattern.

Syn :grep –n pattern file/s

Example :grep –n “sem-6” cource.txt

12) –b

Function : This option is used to display the character position of the matchedstring in a file.

Syn :grep –b pattern file/s

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 65


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Example :grep –b “sem-6” cource.txt

1. Searching for a string in multiple files.

grep "string" file1 file2

2. Specifying the search string as a regular expression pattern.

grep "^[0-9].*" file.txt

3. Displaying the non-empty linesYou can remove the blank lines using the grep command.

grep -v "^$" file.txt

4. Matching the lines that start with a stringThe ^ regular expression pattern specifies the start
of a line. This can be used ingrep to match the lines which start with the given string or pattern.

grep "^start" file.txt

5. Matching the lines that end with a stringThe $ regular expression pattern specifies the end
of a line. This can be used ingrep to match the lines which end with the given string or pattern.

grep "end$" file.txt

(19) sed (Stream EDitor)

Use : This command is used to search a string in a file and replace by another

string. It is also delete, insert and search a string in a file.

Syn :sed ‘s/searchstring/replacestring/[option]’ filename

Example :sed ‘s/abc/rajkumar’ student.dbf

(1) Replacing the nth occurrence of a pattern in a line.

Use : This form of sed command find nth occurrence of a string in a line and replace with a
new string.

Syn :sed ‘s/searchstring/replacestring/nth’ file

Example :sed ‘s/the/that/2’ myapplication.txt

(2) Replacing all the occurrence of the pattern in a line

Use : This form of sed command find all the occurrence of a string and replace with a new
string. Here g means “globle”.

Syn :sed ‘s/searchstring/replacestring/g’ file

Example :sed ‘s/then/than/g’ abstract.doc

(3) Replacing from nth occurrence to all occurrences in a line.

Use : This form of sed command find all the occurrence of a string from nth position and from
there replace all the with a new string.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 66


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Syn :sed ‘s/searchstring/replacestring/Ng’ file //here N means number of position

Example :sed ‘s/than/then/4g’ myapplication.txt

(4) Duplicating the replaced line with /p flag

Use : This form of sed command find all the occurrence of a string and replace with a new
string and display that lines twice on the screen.

Syn :sed ‘s/searchstring/replacestring/p’ file

Example :sed ‘s/ram/rajkumar/p’ student.txt

(5) Printing only the replaced lines

Use : This form of sed command find all the occurrence of a string and replace with a new
string and display only replaced lines.

Syn :sed –n ‘s/searchstring/replacestring/p’ file

Example :sed –n ‘s/ram/rajkumar/p’ student.txt

(6) Replacing string on a specific line number.

Use : This form of sed command find all the occurrence of a string and replace with a new
string at specified line number.

Syn :sed ‘linenumber s/searchstring/replacestring’ file

Example :sed ‘4 s/ram/rajkumar/’ student.txt

(7) Replacing string on a range of lines.

Use : This form of sed command find all the occurrence of a string and replace with a new
string at range of specified line numbers.

Syn :sed ‘startlinenumber,endlinenumber s/searchstring/replacestring/’ file

Example :sed ‘4,9 s/ram/rajkumar/’ student.txt

(8) Deleting lines.

(1) Use : This form of sed command delete specified line.

Syn :sed ‘linenumber d’ file

Example :sed ‘4 d’ student.mdb

(2) Use : This form of sed command delete lines from specified number to end of file.

Syn :sed ‘linenumber,$ d’ file

Example :sed ‘4, $ d’ student.mdb

(9) Duplicating lines

Use : This form of sed command display each line twice.


CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 67
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Syn :sed ‘p’ file

Example :sed ‘p’ student.dbf

(10) Add a line after a match.

Use : This form of sed command add a new line after it find a match string line.

Syn :sed ‘/searchstring/ a “type a new line”’ file

Example :sed ‘/linux/ a “my first linux file”’ linuxmaterial.doc

(11) Add a line before a match

Use : This form of sed command add a new line before it find a match string line.

Syn :sed ‘/searchstring/ i “type a new line”’ file

Example :sed ‘/linux/ i “my first linux file”’ linuxmaterial.doc

Understanding Jobs(Process), Process Commands


What is job(process)? Explain jobs related commands with syntax and suitable example.

Every command you give is a job that is executed. A job can be suspended, placed in the
background, moved back to the foreground or terminated.

Most commands like ls are executed fast, but things like moving huge files occupy your
terminal for quite a while. In these cases the job can be placed in the background, allowing you
to execute other commands in the meantime.

While running a command (job) you can pause/suspend it with ctrl-z and kill it with ctrl-c.

When a job is suspended it can be moved back to the foreground with `fg` and placed in the
background (where it will continue to execute) with `bg`.

(1) ps (Process Status)

Use : It is used to display status of the running process.

Syn :ps [option]

Example :ps

Options :

1) -e

Function : This option used to display all the processes.

Syn :ps –e

Example :ps –e
CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 68
SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2) –f

Function : This option used to display full format listing.

Syn :ps –f

Example :ps –f

3) –u

Function : This option is used to displays the process that belongs to a specific username.

Syn :ps –u username

Example :ps –u abc

(2) time :

Use : It is used to executes command or program and displays time use on the terminal. Here,
time usage is displayed in form of three different time values :

(1) Real time : Total time from the invocation of the command till its termination.

(2) User time : Actual time spent by program in execution of itself.

(3) System time : Time spent by kernel in doing work behalf of the user precess.

Syn : time command/program

Exam : time cat

(3) kill :

Use : It is used to terminate a process having process ID pid.

Syn : kill –[Signal] pid

Exam : kill -9 127

User Commands
Explain user commands in detail.

(1) who

Use : This command is used to display who is working at present on the system.

Syn : who [option]

Example : who

Options :

1) -b

Function : This option used to Indicate the time and date of the last reboot.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 69


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Syn : who –b

Example : who –b

2) –l

Function : This option is used to display information on system login processes

Syn : who –l

Example : who –l

3) –m

Function : This option is used to display the hostname and user associated withstdin.

Syn : who –m

Example: who –m

4) –r

Function : This option is used to display the current run level.

Syn : who –r

Example : who –r

5) –u

Function : This option is used to display the list of user logged in.

Syn : who –u

Example : who –u

6) –q

Function : This option is used to display Get number of users logged-in and their user names.

Syn : who –q

Example : who –q

7) –a

Function : This option is used to display all the information.

Syn : who –a

Example : who –a

Misc Commands
Explain expr command with all its options.

(1) expr

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 70


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Use : This command is used to evaluate expression. You have to provide the space between
the values and the operands. Otherwise the expr command may throw error or print them as a
string.

Syn :expr expression

Example: expr 5 + 6

Output :

11

(1) Arithmetic Operator Examples:

1. Sum of numbers

$ expr 5 + 3

$ expr 1 + 2 + 3

$ expr 5+3

5+3

Here in the third expr command, space is not provided between the literals. The expr command
treated it as a string and printed on the terminal.

2. Difference between two numbers

$ expr 10 - 6

3. Multiplying numbers

$ expr 7 \* 9

63

Here the * is shell builtin operator, that is why it needs to escaped with backslash.

4. Dividing numbers

$ expr 6 / 4

The division operator returns only the arithmetic quotient.

5. Remainder or modulus

$ expr 6 % 4

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 71


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2

(2) Comparision or Relational Operator Examples:

You can use the following comparison operators with the expr command:

• Val1 <Val2 : Returns 1 if val1 is less than val2. Otherwise zero.

• Val1 <= Val2 : Returns 1 if val1 is less than or equal to val2. Otherwise zero.

• Val1 >Val2 : Returns 1 if val1 is greater than val2. Otherwise zero.

• Val1 >= Val2 : Returns 1 if val1 is greater than or equal to val2. Otherwise zero.

• Val1 = Val2 : Returns 1 if val1 is equal to val2. Otherwise zero.

• Val1 != Val2 : Returns 1 if val1 is equal to val2. Otherwise zero.

• val1 | val2 : Returns val1 if val1 is neither null nor zero. Otherwise val2.

• val1 &val2 : Returns val1 if both val1 and val2 is neither null nor zero. Otherwise 0.

Note: You have to escape most of the operators with backslash as they are shell built in.

$ expr 1 \< 2

$ expr 1 \<= 1

$ expr 2 \> 5

$ expr 2 \>= 5

$ expr 7 = 7

$ expr 9 != 18

$ expr 2 \| 5

$ expr 0 \| 5

$ expr 2 \& 5

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 72


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
2

$ expr 6 \& 3

$ expr 6 \& 0

$ expr 0 \& 3

(3) String Function Examples:

1. Length of string

The length function is used to find the number of characters in a string.

$ expr length linux

$expr length linux\ system

12

$expr length "linux system"

If you have spaces in your string escape them with backslash or quote them with double quotes.

2. Find Substring

You can extract a portion of the string by using the substr function. The syntax of substr
function is

substr string position length Here position is the character position in the string. length is the
number of

chracters to extract from the main string. An example is shown below:

$ exprsubstrunixserver 5 6

server

3. Index of the substring You can find the position of a string in the main string using the index

function. The syntax of index function is shown below:

index string chars If the chars string is found in the main string, then the index function returns
the position of the chars. Otherwise it returns 0. See the following examples:

$ expr index linuxnux

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 73


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
$expr index linux win

4. Matching a regexp

The match function is used to find anchored pattern match of regexp in the string. The syntax
of match function is shown below:

match string pattern

The match function returns the number of characters in the pattern is a match is found.
Otherwise, it returns 0. Alternative synatx is

string : pattern

The following examples shows how to use the match function:

$ expr match linuxserverlin

$ expr match linuxserver server

Explain following miscellaneous commands of Linux.

(2) tee:

Use : It is used to splits input into two components. Saves one component in a file and displays
the other to the standard output.

Syn :tee file input

Exam : who | tee user.txt

(3) read

Use : This command is used to take a value from user.

Syn : read variable name

Example : read nam

(4)man :

Use : it is used to display help about command, system calls or function.

Syn : man command

Exam : man ls

(5) cal (Calendar) :

Use : It is used to display calendar.

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 74


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
Syn :

(1) cal :

Display calendar of the current year.

Exam :cal

(2) cal year

It is display calendar of the particular year.

Exam :cal 1998

(3) cal month year

It is display calendar of the particular month of particular year.

Exam :cal 3 2013

(6) date :

Use : it is used to display current date and time.

Syn : date

(7) echo

Use : This command is used to display message or value of variable/s.

Syn : echo [option] message or $variablename

Example : echo “rajesh is my friend” or echo $a

Options:

1) –n

Function : This option do not output the trailing newline.

Syn : echo –n message or $variable

Example : echo –n “my name is xyz”

2) –e

Function : This option enable interpretation of the backslash-escaped characters.

Syn : echo –e “message \escaped character”

Example ; echo –e “my pen is on the table \a”

Note :If-e is in effect, the following sequences are recognized:

\\ Backslash

\a alert (BELL)

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 75


SHREE MARUTI VIDHYAMANDIR COLLEGE OF BUSSINESS
MANGEMNET AND COMPUTER SCIENCE – B.C.A BHAVNAGAR
\b Backspace

\c produce no further output.

\e Escape

\f form feed

\n new line

\r carriage return

\t horizontal tab

\v vertical tab

Keyboard command using ctrl key.

CTRL+B Moves the cursor backward one character.

CTRL+C Cancels the currently running command.

CTRL+D Logs out of the current session.

CTRL+F Moves the cursor forward one character.

CTRL+H Erase one character. Similar to pressing backspace.

CTRL+P Paste previous line(s).

CTRL+S Stops all output on screen (XOFF).

CTRL+Q Turns all output stopped on screen back on (XON).

CTRL+U Erases the complete line.

CTRL+W Deletes the last word typed. For example, if you typed 'mv file1 file2' this shortcut
would delete file2.

CTRL+Z Cancels current operation, moves back a directory or takes the current operation and
moves it to the background

CC-403-ADVANCE OPERATING SYSTEM AND LINUX Page 76

You might also like