14 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
Medium 9789381159057

Exercise

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

E X E RC IS E S 183

E X E R C ISE S

1. E xp lain the system stru ctu re of U N IX op erating system .

2. D escribe the file and d irectory stru ctu re of U N IX .

3. D efine op erating system services.

4. H ow m any level u sed by a p rocess w hen p rocess is ru nning on U N IX system ? D escribe in d etail.

5. D raw the block d iagram of the system kernel. A nd exp lain its w orking.

6. W hat is the p rocess and context of a p rocess? D efine p rocess states and transition.

7. W hat shou ld hap p en? If the kernel attem p ts to aw aken all p rocess sleep ing on an event, bu t no p rocess are asleep on the event at the tim e of the w akeu p .

8. W hat is the bu ffer head er and d u ring system initialization w hy kernel allocates sp ace for a nu m ber of bu ffers. Su p p ose the kernel d oes a d elayed w rite of a block. W hat hap p ens w hen another p rocess takes that block from its hash qu eu e? From the free list?

9. In the algorithm getblk (A lgorithm for buffer allocation),if the kernel rem oves the bu ffer from the free list,it m u st raise the p rocessor p riority level to block ou t interru p ts before checking the free list. W hy?

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

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

50

U NIX

AND

unlock

S HELL P ROGRAMMING

(inode);

return (user file descriptor);

}

The Kernel searches the file system for the file name parameter. It checks permission for opening the file after it finds the incore inode and allocates an entry in the file table for the open file. The file table entry contains a pointer to the inode of the open file and a field that indicates the byte offset in the file where the Kernel expects the next read or write to begin. The Kernel initializes the offset to O during the open call, meaning that the initial read or write starts at the begining of a file by default. The entry in the user file table points to the entry in the global file table.

User file

Descriptor table

Inode table

File table

0

1

2

3

4

5

6

7

Count

2 (etc/passed) count Read

Count

1

Rd-wrt

Count

1 (local)

count 1 write

Fig. 7.1 Data structures after open

fd1 = Open (“/etc/passwd”, O – RDONLY); fd2 = Open (“local”, O – RDWR); fd3 = Open (“/etc/passwd”, O – WRONLY);

The first three user file description (0, 1, 2) are called the standard i/p standard o/p and standard error file descriptors.

See All Chapters
Medium 9789381159057

Ch-13

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

128

U NIX

AND

S HELL P ROGRAMMING

13

Chapter

AWK

AND

P ERL P ROGRAMMING

13.1 INTR

ODUCTION TO A

WK

INTRODUCTION

AWK awk is a simple and elegant pattern scanning and processing language. I would call it the first and last simple scripting language. awk is a little programming language, with a syntax close to C in many aspects. It is an interpreted language and the awk interpreter processes the instructions.

About the syntax of the awk command interpreter itself: awk is also the most portable scripting language in existence. It was created in late 70th of the last century almost simultaneously with Borne shell. The name was composed from the initial letters of three original authors Alfred V. Aho, Brian W. Kernighan, and Peter J. Weinberger.

It is commonly used as a command-line filter in pipes to reformat the output of other commands.

It’s the precursor and the main inspiration of Perl. Although originated in Unix it is available and widely used in Windows environment too. awk takes two inputs: data file and command file. The command file can be absent and necessary commands can be passed as augments. As Ronald P. Loui aptly noted awk is very underappreciated language.

See All Chapters

See All Chapters