14 Slices
Medium 9789381159057

Ch-8

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

70

U NIX

AND

S HELL P ROGRAMMING

Chapter

STRUCTURE

OF A

8

P ROCESS

The Kernel contains a process table with an entry that describes the state of every active process in the system. The u-area contains additional information that controls the operation of a process. The process table entry and the u-area are part of the context of a process. The aspect of the process context that most visibly distinguishes it from the context of another process is of course, the contents of its address space.

8.1 PROCESS STATES AND TRANSITIONS

The following list contains the complete set of process states.

(i)

The process is executing in user mode.

(ii)

The process is executing in Kernel mode.

(iii)

The process is not executing but is ready to run as soon as the Kernel schedules it.

(iv)

The process is sleeping and resides in main memory.

(v)

The process is ready to run, but the swapper (schedule process O) must swap the process into main memory before the Kernel can schedule it to execute.

(vi)

The process is sleeping and the swapper has swapped the process to secondary storage to make room for other processes in main memory.

See All Chapters
Medium 9789381159057

Ch-11

Anoop Chaturvedi ; B.L. Rai Laxmi Publications PDF

SOCKETS

97

11

Chapter

SOCKETS

Furthermore, the methods may not allow processes to communicate with other processes on the same m/c because they assume existence of a server process that sleeps in a driver open or read system call. To provide common methods for IPC and to allow use of sophisticated n/w protocols, the BSD system provides a mechanism known as sockets.

Client Process

Server Process

Socket layer

Protocol layer

Socket layer

TCP

Protocol layer

IP

Device layer

TCP

IP

Device layer

Ethernet

Driver

Ethernet

Driver

N/W

Fig. 11.1 Sockets model

The Kernel structure consists of three parts:

(i)

Socket Layer—Provide the interface b/w the system calls and the lower layers.

(ii)

Protocol Layer—Contains the protocol modules used for communication (e.g., TCP/IP).

(iii)

Device Layer—Contains the device driver that control the n/w devices.

Layer combinations of protocols and drivers are specified when configuring the system.

Process communicate using the client server model; a server process listens to a socket one end point of a two way communication path, and client process communicate to the server process cover another socket, the other end point of communications path which may be on another m/c. The Kernel maintains internal connections and routes data from client to server.

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

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

See All Slices