14 Slices
Medium 9789381159057

Ch-1

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

2

U NIX

AND

S HELL P ROGRAMMING

Kernel → This is the name of UNIX Operating System.

Shell → This is the command interpreter used in unix.

Application programs and utilities —Utilities are UNIX commands. Application programs such as word processor, spreadsheets and Database Management Systems may be installed along side the linux (or UNIX) commands. A user may run a utility or Application Programs through shell.

User

(i)

Ordinary user → Work only their own working directory.

(ii)

Super user → Super user have the command on entire system. They can add user.

Remove user etc.

1.2 TYPES OF SHELL

(i)

(ii)

Bourne Shell—It was created by Steve Bourne probably that’s why its bounded with every UNIX system. Because it was bounded with every system it became popular.

Whatever the cause and the effect, the fact remains that this is the shell used by many

UNIX users.

C Shell—It was created by “Bill Joy” then pursuing his graduation at the University of California at Berkeley. This shell is a hit with those who are seriously into UNIX programming. It has two advantage over Bourne Shell.

See All Chapters
Medium 9789381159057

Ch-12

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

U NIX C OMMAND 103

Chapter

12

UNIX COMMAND

12.1 INTRODUCTION TO SHELL

The Shell is a program that provides an interpreter and interface between the user and the

UNIX Operating System. It executes commands that are read either from a terminal or from a file.

Files containing commands may be created, allowing users to build their own commands. In this manner, users may tailor UNIX to their individual requirements and style.

There are a number of different Shells. Each provides a slightly different interface between the user and the UNIX Operating System. There are three important types of shell in UNIX these are:

(i)

Bourne Shell

(ii)

C-Shell

(iii)

Korn Shell

There are other shells that are less widely used and not available on many machines. A command issued by a user may be run in the present shell, or the shell itself may start up another copy of itself in which to run that command. In this way, a user may run several commands at the same time. A secondary shell is called a sub-shell.

When a user logs onto the system, a shell is automatically started. This will monitor the user’s terminal, waiting for the issue of any commands. The type of shell used is stored in a file called passwd in the subdirectory etc. Any other shell may be run as a sub-shell by issuing it as a command. For example, /usr/bin/ksh will run a Korn shell. The original shell will still be running—in background mode—until the Korn shell is terminated.

See All Chapters
Medium 9789381159057

Ch-3

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

12

U NIX

AND

S HELL P ROGRAMMING

Chapter

3

FILE SYSTEM

After the disk has been partitioned its still not ready for use. A file system has to be created in each partition. There usually are multiple file systems in one m/c each one having its own directory tree headed by root.

Every file system is organized in a sequence of blocks of 512 bytes each. (1024 in Linux) and will have there four components:

Boot Block

Super Block

Inode Blocks

Data Block

3.1 FILE SYSTEM LAYOUT

1.

Boot Block—This block contains a small boot strap program. This is the Master Boot

Record (MBR) that DOS users would like to call it. This is loaded into memory when the system is booted. It may in turn load another program from the disk but eventually it will load the Kernel (the file/stand/unix or/vm linuz) into memory.

2.

Super Block—It describe the state of file system (balance sheet of every UNIX file system). The Kernel first reads this area before allocating disk blocks and inodes for new files. The super block contains global file information about disk usage and availability of data blocks and inodes. It contains:

See All Chapters
Medium 9789381159057

Ch-10

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

90

U NIX

AND

S HELL P ROGRAMMING

Chapter

10

INTER -PROCESS COMMUNICATION

IPC mechanism allow arbitrary process to exchange data and synchronize execution.

We have already considered several forms of interprocess communication, such as pipes, named pipes and signals. Pipes suffer from the drawback that they are known only to processes which are descendants of the process that invoke the pipe system call: unrelated process cannot communicate via pipes. Although named pipe allow unrelated process to communicate, they cannot generally be used across a network nor do they readily lend themselves to setting up multiple communications paths for different sets of communicating process: its impossible to multiplex a named pipe to provide private channels for pairs of communicating process. Arbitrary process can also communicate by sending signals via the kill system call, but the message consist only of the signal number.

10.1 PROCESS TRACING

One process traces and controls the execution of another process. Tracing processes, useful for debugging. A debugger process such as sdb, spawns a process to be traced and controls its execution with the ptrace system call, setting and clearing break points, and reading and writing data in its virtual address space.

See All Chapters
Medium 9789381159057

Ch-6

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

42

U NIX

AND

S HELL P ROGRAMMING

Chapter

INODE A SSIGNMENT

TO A

6

NEW F ILE

The file system contains a linear list of inodes. An inode is free if its type field is zero. When a process needs a new inode, the Kernel could theoretically search the inode list for a free node.

However, such a search would be expensive, requiring atleast one read operation for every inode.

To improve performance, the file system super block contains an array to cache the numbers of free inodes in the file system.

For assigning new inodes. The Kernel first verifies that no other processes have locked access to the super block free inode list. If the list of inode numbers in the super block is not empty the

Kernel assigns the next inode number, allocates a free incore inode for the newly assigned disk inode copies the disk inode to the incore copy initilizes the fields in the inode and returns the locked inode. It updates the disk inode to indicate that the inode is now in use. A non zero file type field indicates that the disk inode is assigned.

See All Chapters

See All Slices