Download Ch2

Post on 02-Nov-2014




0 download

Embed Size (px)


operating system and design chapter2


  • 1. Introduction to Kernel Prepared byChandni Shah

2. Introduction to KernelTopics Kernel Architecture Introduction To System Concepts File System Process Kernel Data Structures System Administration 3. Kernel Architecture (UNIX) User program Library User levelsystem call interfacekernel level Inter process File SubsystemcommunicationBuffer CacheProcess Control SchedulerSubsystemMemorycharacterblock Managemen tDevice driver Hardware controlkernel levelhardware User level 4. Overview of File Subsystem Every file has a I-Node(index node) It contains details like disk layout of file data ,owner,access permissions and access times. I-node is unique to each file in Unix 5. What is an inode?5 An inode (index node) is a control structure that containskey information needed by the OS to access a particular file. Several file names may be associated with a single inode,but each file is controlled by exactly ONE inode. On the disk, there is an inode table that contains the inodesof all the files in the file system. When a file is opened, its inode is brought into mainmemory and stored in a memory-resident inode table. 6. Data Structure for File Handling Inode Table List of all I-nodes Global File table. global to the kernel e.g. the byte offset in the file where theusers next read/write will start the access rights allowed to the opening process. Process File Descriptor table. local to every process contains information like the identifiers of the files opened bythe process. Whenever, a process creates a file, it gets an index from thistable primarily known as File Descriptor. 7. Data Structure for File Handling Inode tables interact with user process specific file descriptor tables and global file tables in Unix File System to facilitate the file handling. 8. 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); 9. File Descriptors, File Table and Inode table 10. Explanation of figure Each open() returns a file descriptor to the process, and thecorresponding entry in the user file descriptor table points toa 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 inodetable entry. Every opened file has a unique entry in the globalfile table and the user file descriptor table but kernel keepsonly single entry per file in the in-core inode table. Separate entries are created in user file descriptor and globalfile table, but only the reference count is increased in theinode table. All the system calls related to file handling use these tablesfor data manipulation. 11. File System A file system is consists of a sequence of logicalblocks (512/1024 byte etc.) A file system has the following structure: Boot Block Super BlockInode List Data Blocks 12. 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 13. 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 14. File System: Inode List Inodes are used to access disk files. Inodes maps the disk files For each file there is an inode entry in the inode listblock Inode list also keeps track of directory structure 15. 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 16. Processes(1) A process is the execution of a program A process is consists of text (machine code), dataand stack Many process can run simultaneously as kernelschedules them for execution Several processes may be instances of oneprogram A process reads and writes its data and stacksections, but it cannot read or write the data andstack of other processes A process communicates with other processes andthe rest of the world via system calls 17. Processes(2) Kernel has a process table that keeps tract of allactive processes Each entry in the process table contains pointers tothe text, data, stack and the U Area of a process. All processes in UNIX system, except the very firstprocess (process 0) which is created by the systemboot code, are created by the fork system call 18. Kernel Support for ProcessKernel ProcessKernel RegionTableA ProcessTable Per Process Region TableTextFile Descriptor Table DataStackU Area 19. Process: Region Table Region table entries describes the attributes of theregion, such as whether it contains text or data,whether it is shared or private The extra level from the per process region table tokernel region table allows independent processes toshare regions. 20. Process: U Area U Area is the extension of process table entry. Fields of process table entry: State field User ID (UID) Fields of U Area Pointer to process table entry File descriptors of all open files Current directory and current root I/O parameters Process and file size limit Kernel can directly access fields of the U Area of the executing process but not of the U Area of other processes 21. Process Context The context of a process is its state: Text, data( variable), register Process region table, U Area, User stack and kernel stack When executing a process, the system is said to be executing in the context of the process. 22. Context Switch When the kernel decides that it should executeanother process, it does a context switch, so that thesystem executes in the context of the other process When doing a context switch, the kernel savesenough information so that it can later switch backto the first process and resume its execution. 23. Mode of Process Execution(1) The UNIX process runs in two modes: User mode 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 24. Mode of Process Execution(2) When moving from user to kernel mode, the kernelsaves enough information so that it can later returnto user mode and continue execution from where itleft off. Mode change is not a context switch, just change inmode. 25. Process StatesProcess states are: The process is running in user mode The process is running in kernel mode The process is not executing, but it is ready to run as soon as the scheduler chooses it The process is sleeping Such as waiting for I/O to complete 26. Process State Transition(1) user running 1 system callreturnor interrupt Interrupt returnkernel running 2 sleep schedule processasleep 3 ready to run 4 wakeup context switchpermissible 27. Process State Transition(2) The kernel allows a context switch only when aprocess moves from the state kernel running to thestate asleep Process running in kernel mode cannot bepreempted by other processes. 28. Fork System Call(1) When a process is created by fork, it containsduplicate copies of the text, data and stack segmentsof its parent Also it has a File Descriptor Table (FDT) thatcontains references to the same opened files as itsparent, such that they both share the same filepointer to each opened file 29. Fork System Call(2) stack Region table dataParent U AreatextChildstack U Area data Region table Kernel File Kernel Region Table Table