Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Chapter 1: Introduction to Unix / Linux Kernel

3,280 views

Published on

Brief introduction about unix kernel , levels, file system and so on

Published in: Education
  • Login to see the comments

Chapter 1: Introduction to Unix / Linux Kernel

  1. 1. Advanced Operating Systems Unit I Introduction to UNIX/Linux Kernel By, Ashvini Chaudhari
  2. 2. Prerequisites: 1. Working knowledge of C programming. 2. Basic Computer Architecture concepts. 3. Basic algorithms and data structure concepts.
  3. 3. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad History • 1965, AT&T Bell Lab & GE (General Electric Company) & Project MAC of MIT : Multics • Ken Thompson & Dennis Ritchie :UNICS • 1971, UNIX was tried on more powerful machine PDP-1 • 1972, Dennis Ritchie developed ‘C’ language • 1977, it was first ported (or say installed) on Non-PDP machine called Interdata 8/32. • 1982, AT&T itself created UNIX System III (for commercial purpose), UNIX System IV (only for its internal use) • Jan 1983, the UNIX System V Last Version • Due to availability of source code, University California in Berkeley, developed their own UNIX standard for VAX machine, which was called as UNIX 4.3 BSD (Berkeley Software Distribution). •
  4. 4. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Why Unix is popular • easy to read, easy to understand, easy to move to other machines. • It has easy user interface, • Complex programs can be built by combining existing simple programs (obviously by using pipe). • It uses Hierarchical file system, which is easy to maintain & implement. • In UNIX, everything storable is “file”, means device, terminals, even directories are also files. UNIX considers “file” as stream of byte. Thus system programming becomes easy. • It is Multi-user, Multi-tasking, Multi-threading operating system. • It hides hardware (i.e. machine architecture) from the programmer & end user. • Though system was written in C, it provides environmental support to other languages like Basic, Fortran, Pascal, ADA, Cobol, Lisp, Prolog, C++, Java, etc.
  5. 5. The Basic System Architecture
  6. 6. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad • This interaction (i.e. communication of application program with the Kernel) is done by a set of functions known as System Calls. In UNIX System Release V, there are such 64 system calls, out of which 32 system calls are sued much frequently. •
  7. 7. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Features • The high-level features of UNIX system, mainly includes 3 points : • The File System. • The Processing Environment. • The Building Block Primitives.
  8. 8. Sample File System Tree Absolute Path Relative Path
  9. 9. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Characteristics ▫ A hierarchical (i.e. tree like) structure. ▫ Consistent treatment to file data (i.e. all files are stream of bytes). ▫ Ability to create new & to delete old files. ▫ Dynamic growth of files. ▫ The protection of file data (by access permissions) ▫ Peripheral devices & directories are also considered as files. •
  10. 10. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad • “Files in UNIX are unformatted stream of bytes” and system treats them with same system calls assessment. • Thus “copy oldfile newfile” command will operate on any type of file, whether it is a regular file or directory file or device file. •
  11. 11. Processing Environment • A program is an executable file, and a process is an instance of the program in execution .Many process can execute simultaneously on UNIX system with no logical limit to their number ,and many instances of a program can exist simultaneously in the system .
  12. 12. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad • The major 4 system calls for process management are fork ( ), • exec ( ), • wait ( ) and • exit ( ), where fork ( ) is used to create a new process, exec ( ) is used to execute the new process, wait ( ) is used to allow the old process to wait for the completion of the execution of new process and exit ( ) is used for exiting the program
  13. 13. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad • When exec ( ) executes a child process, the child process overlaps (or more precisely overlays) the address space (memory) of parent process. And thus there remains no memory for parent process to run, thus parent process must wait for the completion of execution of child.
  14. 14. User Perspective • the fork system call to create a new process. The new process, called the child process, gets a 0 return value from fork and invokes execl • The execl call overlays the address space of the child process with the file "copy“. • If the execl call succeeds, it never returns because the process executes in a new address space meanwhile, the process that had invoked fork (the parent) receives a non-0 return from the call, calls wait:, suspending its execution until copy finishes, prints the message "copy done," and exits
  15. 15. User perspective: Shell • The shell allows three types of commands. • First, a command can be an executable file that contains object code produced by compilation of source code (a C program for example). • Second, a command can be an executable file that contains a sequence of shell command lines • The internal commands make the shell a programming language in addition to a command interpreter and include commands for looping
  16. 16. User Perspective : Building Block Primitives • redirect I/O • Processes conventionally have access to three files: they read from their standard input file, write to their standard output file, and write error messages to their standard error file.
  17. 17. User Perspective : Building Block Primitives • Pipe • The pipe, a mechanism that allows a stream of data to be passed between reader and writer processes. Processes can redirect their standard output to a pipe to be read by other processes that have redirected their standard input to come from the pipe. • The data that the first processes write into the pipe is the input for the second processes. The second processes could also redirect their output, and so on, depending on programming need. Again, the processes need not know what type of file their standard output is;they work regardless of whether their standard output is a regular file, a pipe, or a device
  18. 18. Operating System Functions ▫ Process creation, termination, suspension and inter-process communication. ▫ CPU scheduling for multiple processes in “time- shared” manner. (here it is assumed that system has one CPU) ▫ Memory allocation (either by swapping or paging) for executing process/processes. ▫ File I/O, by creating file system. ▫ Insulates processes from hardware of the machine.
  19. 19. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Assumptions about h/w • A process (i.e. running program) runs in two modes : - Kernel Mode & User Mode. • Kernel Mode : When a process makes a system call, then it said that, now the process is running in Kernel Mode. • User Mode : When the process is doing operations like assignments, comparisons, looping, then it is said that, now the process is running in User Mode.
  20. 20. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Interrupts : • While handing the interrupts, Kernel gives first preference to high priority interrupts and then to low priority interrupts. • The priority of the interrupt is usually decided by the hardware itself.
  21. 21. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Exceptions : • Exception is an un-excepted event caused by a process. E.g. – Addressing illegal memory by using pointer, execution of un- allowed instruction (like dividing by 0) etc. • Interrupts occur by the events which are external to the process while exception occurs “in the middle” of the process due to code instruction. • It is also said that, interrupt occurs between the two instructions and exception occurs at the instruction (obviously at illegal instruction). • For interrupt, system starts the next instruction normally after handling the interrupt. • But for exception, system handles the exception, and then either re-starts the same instruction
  22. 22. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Processor Execution Level • If a processor execution level is set to “Disk Interrupt Level” (see in figure), then only “System Clock” & “Machine Error” interrupts are processed and remaining all lower level interrupts (including the set level) are prevented • During & Critical Activity • Privileged Instructions :
  23. 23. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Memory Management : • If sufficient memory is available, then Kernel can assign memory to the program’s process by methods of memory management, like swapping or demand paging.
  24. 24. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Unix System Architecture
  25. 25. Assumptions about Hardware user VS kernel 1. Processes in user mode can access their own instructions and data but not kernel instructions and data (or those of other processes). Processes in kernel mode,however, can access kernel and user addresses. 2. Some machine instructions are privileged and result in an error when executed in user mode.
  26. 26. Concepts of Linux Programming Files and the File system 1. The file is the most basic and fundamental abstraction in Linux. Linux follows the everything-is-a-file 2. In order to be accessed, a file must first be opened. Files can be opened for reading, writing, or both 3. An open file is referenced via a unique descriptor, a mapping from the metadata associated with the open file back to the specific file itself. Inside the Linux kernel, this descriptor is handled by an integer (of the C type int) called the file descriptor, abbreviated fd.
  27. 27. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Files and the Filesystem • Regular files • What most of us call “files” are what Linux labels regular files. A regular file contains bytes of data, organized into a linear array called a byte stream. In Linux, no further organization or formatting is specified for a file. • Directories and links • Accessing a file via its inode number is cumbersome so files are always opened from user space by a name, not an inode number. • Directories are used to provide the names with which to access files. A directory acts • as a mapping of human-readable names to inode numbers. A name and inode pair is • called a link. The physical on-disk form of this mapping a simple table, a hash, or • Whatever is implemented and managed by the kernel code that supports a given • filesystem. Conceptually, a directory is viewed like any normal file, with the difference • that it contains only a mapping of names to inodes. The kernel directly uses this • mapping to perform name-to-inode resolutions.
  28. 28. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Files and the File system • Hard links • Conceptually, nothing covered thus far would prevent multiple names resolving to the same inode. Indeed, this is allowed. When multiple links map different names to the same inode, we call them hard links. • Hard links allow for complex filesystem structures with multiple pathnames pointing to the same data. The hard links can be in the same directory, or in two or more different directories.
  29. 29. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Files and the File system • Symbolic links • Hard links cannot span filesystems because an inode number is meaningless outside of the inode’s own filesystem. To allow links that can span filesystems, and that are a bit simpler and less transparent, Unix systems also implement symbolic links (often shortened to symlinks). • Symbolic links look like regular files. A symlink has its own inode and data chunk, which contains the complete pathname of the linked-to file. This means symbolic links can point anywhere, including to files and directories that reside on different filesystems, and even to files and directories that do not exist. A symbolic link that points to a nonexistent file is called a broken link.
  30. 30. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Users and Groups • Authorization in Linux is provided by users and groups. Each user is associated with a unique positive integer called the user ID (uid). Each process is in turn associated with exactly one uid, which identifies the user running the process, and is called the process’ real uid. Inside the Linux kernel, the uid is the only concept of a user. Users themselves, however, refer to themselves and other users through usernames, not numerical values. Usernames and their corresponding uids are stored in /etc/passwd, and library routines map user-supplied usernames to the corresponding uids.
  31. 31. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Permissions
  32. 32. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Signals • Signals are a mechanism for one-way asynchronous notifications. A signal may be sent from the kernel to a process, from a process to another process, or from a process to itself. Signals typically alert a process to some event, such as a segmentation fault, or the user pressing Ctrl-C.
  33. 33. Prof.Prasad Sawant ,Assitiant Professor ,Dept. Of CS PCCCS Chichwad Inter process Communication • Allowing processes to exchange information and notify each other of events is one of an operating system’s most important jobs.

×