The document discusses key concepts related to kernel architecture, processes, and file handling in operating systems. It covers topics such as inodes, process tables, file descriptors, context switching, fork system calls, and the interaction between inodes, file tables, and process file descriptor tables when files are opened. The main components of a file system like boot blocks, super blocks, inode lists, and data blocks are also summarized.
2. Kernel Architecture (UNIX)
Library
hardware
File Subsystem
character block
Hardware control
Buffer Cache
system call interface
Device driver
Inter process
communication
Scheduler
Memory
Managemen
t
Process Control
Subsystem
User program
User level
kernel level
User level
kernel level
3. What Is An Inode?
• An inode (index node) is a control structure that contains key
information needed by theOSto accessaparticular file.
• Several file names may be associated with a single inode, but each file
iscontrolled by exactly ONE inode.
• On the disk, there is an inode table that contains the inodes of all the
filesin thefilesystem.
• When a file is opened, its inode is brought into main memory and
stored in amemory-resident inodetable.
3
4. Data Structure for File Handling
• InodeTable
• List of all I-nodes
• Global Filetable.
• global to the kernel e.g. the byte offset in the file where the user's next read/write
will start
• theaccessrightsallowed to theopening process.
• ProcessFileDescriptor table.
• local to every process
• containsinformation liketheidentifiersof thefilesopened by theprocess.
• Whenever, a process creates a file, it gets an index from this table primarily known
as FileDescriptor.
5. Interaction Between Tables With An Example
• ExamplE:
• procEss a:
fd1 = opEn("/var/filE1", o_rdonlY);
fd2 = opEn("/var/filE2", o_rdWr);
fd3 = opEn("/var/filE1", o_WronlY);
•
• procEss B:
fd1 = opEn("/var/filE1", o_rdonlY);
fd2 = opEn("/var/filE3", o_rdonlY);
7. Explanation Of Figure
•Each o pe n() returns a file descriptor to the process, and
the corresponding entry in the user file descriptor
table points to a unique entry in the global file table even
though a file(/var/file1) is opened more then once.
•These global file table entries map to the in-core inode
table entry. Every opened file has a unique entry in the
global file table and the user file descriptor table but
kernel keeps only single entry per file in the in-core
inode table.
•Separate entries are created in user file descriptor and
global file table, but only the reference count is
increased in the inode table.
8. File System
•A file system is consists of a sequence of logical blocks
(512/1024 byteetc.)
•A filesystem hasthefollowing structure:
Boot Block Super Block Inode List Data Blocks
9. File System: Boot Block
•The beginning of the file system
•Contains bootstrap code to load the
operating system
•Initialize the operating system
•Typically occupies the first sector of the
disk
10. File System: Super Block
•Describes the state of a file system
•Describes the size of the file system
•How many files it can store
•Where to find free space on the file
system
•Other information
11. File System: Inode List
•Inodesareused to accessdisk files.
•Inodesmapsthedisk files
•For each filethereisan inodeentry in theinodelist
block
•Inodelist also keepstrack of directory structure
12. File System: Data Block
•Starts at the end of the inode list
•Contains disk files
•An allocated data block can belong to one
and only one file in the file system
13. Processes
•A process is the execution of a
program
•A process is consists of text
(machine code), data and stack
•Many process can run
simultaneously as kernel schedules
them for execution
•Several processes may be instances
of one program
•A process reads and writes its data
14. Processes
• Kernel hasaprocesstablethat keepstract of all activeprocesses
• Each entry in the process table contains pointers to the text, data,
stack and theU Areaof aprocess.
• All processes in UNIX system, except the very first process(process
0) which is created by the system boot code, are created by the fork
system call
15. Kernel Support for Process
Text
Stack
DataFile Descriptor Table
Per Process Region Table
Kernel Process
Table
Kernel Region
TableA Process
U Area
16. Context Switch
•When the kernel decides that it should execute
another process, it does a context switch, so that the
system executes in the context of the other process
•When doing a context switch, the kernel saves
enough information so that it can later switch back to
the first process and resume its execution.
17. Mode of Process Execution
• The UNIX process runs in two modes:
• Usermode
• Can access its own instructions and data, but not kernel
instruction and data
• Kernel mode
• Can access kernel and user instructions and data
• When a process executes a system call, the execution mode
of the process changes from user mode to kernel mode
• When moving from user to kernel mode, the kernel saves
enough information so that it can later return to user mode and
continue execution from where it left off.
• Mode change is not a context switch, just change in mode.
18. Process States
Processstatesare-
•Theprocessisrunning in user mode
•Theprocessisrunning in kernel mode
•Theprocessisnot executing, but it isready to run
assoon asthescheduler choosesit
•Theprocessissleeping
• Such aswaiting for I/O to complete
19. Process State Transition
2
4
1
3asleep
user running
kernel running
ready to run
system call
or interrupt
Interrupt return
schedule processsleep
wakeup
return
context switch permissible
20. Fork System Call
• When a process is created by fork, it contains duplicate copies of the
text, dataand stack segmentsof itsparent
• Also it has a file descriptor table (fdt) that contains references to the
same opened files as its parent, such that they both share the same file
pointer to each opened file
21. Fork System Call
Parent
Child
U Area
U Area
stack
data
text
stack
data
Kernel File
Table
Kernel Region
Table
Region
table
Region
table