1 / 95

CHAPTER 1 What Is Unix?

CHAPTER 1 What Is Unix?. Lecturer: Prof. Andrzej (AJ) Bieszczad Email: andrzej@csun.edu Phone: 818-677-4954. “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National University of Technology (Korea) and NYU.

alta
Download Presentation

CHAPTER 1 What Is Unix?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 1 What Is Unix? Lecturer: Prof. Andrzej (AJ) Bieszczad Email: andrzej@csun.edu Phone: 818-677-4954 “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National University of Technology (Korea) and NYU

  2. CONTENTS • Computer Systems • Hardware • Operating System • Software • Communication • UNIX Features • UNIX Philosophy • UNIX’s History

  3. Operating Systems • Without its software, a computer is useless. • With its software, a computer can store, process, and retrieve information, and engage in many other valuable activities. • Computer software can be roughly divided into two kinds: • the system programsthat manage the operation of the computer itself, • the application programs, which solve problems for their users. • The most fundamental of all the system program is operating system, which controls all the computer’s resources and provides the baseupon which the application programs can be written. • Unix is a popular operating system. It is most commonly used in backend applications, on servers, powerful workstations, etc. One of the most well-designed operating systems of its time. • Linux and MacOS X (basically a BSD Unix) are popular desktop alternatives to MS Windows.

  4. Operating Systems • An operating system • a program that controls the execution of application programs and acts as an interface between the user of a computer and the computer hardware. • An operating system has four major components: • process management, • input/output, • memory management, and • the file system. • Having three objectives or performing three functions: • convenience • efficiency • ability to evolve

  5. Operating Systems • Convenience • An operating system makes a computer more convenient to use. • Efficiency • An operating system allows the computer system resources to be used in an efficient manner. • Ability to evolve • An operating system should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions without at the same time interfering with service.

  6. Layers and Views of a Computer System End User Programmer Or Administrator Application Programs Operating System Designer Utilities Operating System Computer Hardware

  7. Computer Systems • A typical single-user computer system is built out of many parts, including: • a central processing unit( CPU ), • memory, • disks, • a monitor, and • a keyboard. • Computer system is more than hardware. It consists of various hardware and software components. Computer hardware is useless without software. • Computers can be connected together to form larger computer networks, enabling tasks to be distributed among individual computers.

  8. Computer Systems • A Computer System consists of hardware, system programs and application programs. Application programs Banking System Airline Reservation Adventure games Compilers Editors Command Interpreter Operating System Machine language Microprogramming Physical devices System programs Hardware

  9. Computer Hardware • Computer systems, whether large or small, multiuser or single user, expensive or cheap, include most of the following pieces of hardware: • Central processing unit (CPU) • reads machine code(instructions in a form that a computer can understand) from memory and executes it. • A CPU is often thought of as the “brain” of a computer. • Random-access memory (RAM) • holds machine code and data that are accessed by the CPU. • Read-only memory (ROM) • holds both machine code and data. • Its contents may not be changed and are remembered even when the power to the computer is turned off.

  10. Computer Hardware • Disk • holds large amount of data and code on a magnetic or optical medium and remembers it all even when the power to the computer is turned off. • Floppy disks are generally removable from the computer, whereas hard disks are not. • Hard disks can hold a lot more information that floppy disks can. • CD-ROM drive • allows digitally published information on a compact disk to be read by the computer. • Monitor • displays information and comes in two types: monochrome and color.

  11. Computer Hardware • Graphics card • allows the CPU to display information on a monitor. • Keyboard • allows a user to enter alphanumeric information. • Mouse • allows a user easily to position cursors, icons, graphics, text, and other items on the screen by using short movements of the hand. • Printer • allows a user to obtain hard copies of information. • Tape • generally used for making backup copies of information stored on disks.

  12. Computer Hardware • Modem • allows the user to communicate with other computers across a telephone line. • Ethernet interface • allows computers to communicate at high speeds. • Computers attach to an Ethernet by a special piece of hardware called an Ethernet interface. • Other peripherals • many other kinds of peripherals that computer systems can support, including: • graphics tablets, • optical scanners, • array processors, • sound cards, • voice recognition cards, • synthesizers, etc.

  13. programs operating system hardware Operating Systems • A computer system cannot function without an operatingsystem. • There are many different operating systems that are available for PCs, minicomputers, and mainframes; • the most common ones are Windows, VMS, MacOS, and UNIX. • MS Windows is only available for PCs • VMS is only available for mini-computers and mainframes, • and UNIX is available for virtually all platforms.

  14. c programsscripts user lsksh gccfind shell and utilities open()fork()exec() kernel hardware Unix System Structure • Software is a collection of programs available in a computer system.

  15. user shell and utilities kernel hardware Kernel • Manage resources • Storage • Memory • CPU • Display • Network • Sharing • Users • Tasks • Communication

  16. Kernel Subsystems • File system • Directory hierarchy, regular files, peripherals • Multiple file systems • Input/Output • How processes access files, terminal I/O • Process management • How processes share CPU, memory and signals • Scheduling • Interprocess Communication • Memory management • UNIX variants have different implementations of different subsystems.

  17. Kernel Subsystems

  18. Kernel Interactions • Processes accesses kernel facilities via system calls • Peripherals communicate with the kernel via hardware interrupts User Level System Calls Kernel Level Interrupts Hardware Level

  19. Talking to Kernel

  20. Kernel Data Structures User Space • Information about each process is stored in the kernel. • Process table: contains an entry for every process in the system. • Open-file table: contains at least one entry for every open file in the system. Code Data Code Data Code Data Process Info Process Info Process Info Open FileTable ProcessTable Kernel Space

  21. user shell and utilities kernel hardware Shell and Utilities • The rest of the operating system • Focus of this course • Cause of debate in Linux community

  22. UNIX Shell • Shell is the user interface to the operating system • Functionality: • Execute other programs • Manage files • Manage processes • A program like any other • Executed when you log on • How to use shells? • Interactively • When you log in, you interactively use the shell • Scripting • A set of shell commands that constitute an executable program: a script

  23. Files and Processes • A file is a collection of data that is usually stored on disk, although some files are stored on tape. • When a program is started, it is loaded from disk into RAM. When a program is running, it is called a process. • Most processes read and write data from files.

  24. Unix File System • Files are just sequences of bytes • No file types (data vs. executable) • No sections • Example of UNIX philosophy (KISS: keep it simple…) • Directories are lists of files and other directories, along with their status: • creation date • permissions, etc. • Each directory entry links to a file on the disk • two different directory entries can link to the same file • in same directory or across different directories • moving a file does not actually move any data around. • creates link in new location • deletes link in old location • UNIX supports a hierarchical directory structure. • Files and processes have a “location” within the hierarchy of a directory. A process may change its own location and/or the location of a file. • UNIX provides services for the creation, modification, and destruction of programs, processes, and files.

  25. Unix File System • a tiny UNIX directory hierarchy that contains four files and a process running the “sort” utility: / (Root directory) home bin who sort glass tim sort myfile.txt afile.txt : a file : a process

  26. File Pathnames • Two files in the same directory may not have the same name, although it’s perfectly OK for several files in different directories to have the same name. We need pathnames to differentiate between files with the same names located in different directories. • A pathname is a sequence of directory names that leads you through the hierarchy from a starting directory to a target file. • For example, here’s a small hierarchy that contains three files called “myFile” in three separate directories. / home bin myFile glass tim myFile myFile

  27. Absolute Pathnames • A pathname relative to the root directory is often termed an absolute, or full, pathname. /home/glass/myFile /home/myFile /bin/myFile / home bin myFile glass tim myFile myFile

  28. Absolute and Relative Pathnames • A process may also unambiguously specify a file by using a pathname relative to its current working directory. • UNIX file system supports the following special fields that may be used when supplying a relative pathname: Field Meaning . current directory .. parent directory

  29. Relative Pathnames • Relative Pathnames (from /home/glass) myFile or ./myFile ../myFile ../../bin/myFile / home bin myFile glass tim myFile myFile

  30. Disk Architecture

  31. Storing a File • Files are stored in multiple physical blocks on a disk.

  32. Inodes • File inode (index node) contains information about the whereabouts of the “pieces” of the file.

  33. Logical Disk Layout

  34. Directory Organization

  35. Translating Pathnames into Inode Numbers

  36. Symbolic Links • Symbolic links are different than regular links (often called hard links). • Can be thought of as a file that contains the name of another file • Does not change link count for file • When original deleted, symbolic link remains • They exist because: • Hard links don’t work across file systems • Hard links only work for regular files, not directories dirent symlink dirent file file dirent Symbolic Link Hard link

  37. Unix Security • Processes and files have an owner and may be protected against unauthorized access. • A set of users can form a group. A user can be a member of multiple groups. • A special user (id 0, name root) has complete control. • Each user has a primary (default) group. • This scheme is used to determine if file or process operations can be performed: • Can a given file be read? written to? • Can this program be run? • Can I use this piece of hardware? • Can I stop a particular process that’s running?

  38. File and Directory Permissions • UNIX provides a way to protect files based on users and groups. • Three types of permissions: • read, process may read contents of file • write, process may write contents of file • execute, process may execute file • Three sets of permissions: • permissions for owner • permissions for group • permissions for other • Same types and sets of permissions as for files apply to directories: • read: process may read the directory contents (i.e., list files) • write: process may add/remove files in the directory • execute: process may open files in directory or subdirectories

  39. Devices as Special Files • Besides files, input and output can go from/to various hardware devices. • Unix Philosophy: Treat these devices as special files! • Terminals, printers, and other devices are accessible in the same way as disk-based files. / home dev … bin usr … lpr tty modem /dev/lpr /dev/tty /dev/modem

  40. Mounting File Systems • When UNIX is started, the directory hierarchy corresponds to the file system located on a single disk called the root device. • Mounting allows root to splice the root directory of a file system into the existing directory hierarchy. • File systems created on other devices can be attached to the original directory hierarchy using the mount mechanism.

  41. Mounting File System root device external device / / a a b b / Device mountingpoint a / b /a/b a Mount table b

  42. Open File Table • I/O operations are done on files by first opening them, ading/writing/etc., then closing them. • The kernel maintains a global table containing information about each open file. Inode Mode Count Position 1023 read 1 0 1331 read/write 2 50 …

  43. The File Descriptor Table • Each process has contains a table of files it has opened. • Each open file is associated with a number or handle, called file descriptor, (fd). • Each entry of this table points to an entry in the open file table. • Starts at 0 • Why not just file descriptor? • Extra information stored: • Should the open file be inherited by children? (close-on-exec flag) • Convenient for kernel • indirection makes security easier • Numbering scheme can be local to process (0 .. 128)

  44. Stardard Input, Output and Error • The first three entries in the file descriptor table are preset: • Entry 0 is for input • Entry 1 is for output • Entry 2 is for error messages • By default all go to terminal (/dev/tty) FileDescriptorTable 012

  45. Processes • Program: collection of bytes stored in a file that can be run • Image: computer execution environment of program • Process: execution of an image • Unix can execute many processes simultaneously. • Process creation: interesting trait of UNIX • fork system call clones the current process • exec system call replaces current process • A fork is typically followed by an exec • All of the per process information is copied with the fork operation • Working directory • Open files • Before exec, these values can be modified A A A A B

  46. Processes • Program arguments • When a process is started, it is sent a list of strings: argv, argc • The process can use this list however it wants to • Ending a program • When a process ends, there is a return code associated with the process outcome • This is a non-negative integer • 0 means success • anything larger than 0 represent various kinds of failure • The return value is passed to the parent process

  47. Organization of Executable File

  48. Process Composition • signal handling information • file descriptor table • CPU usage statistics

  49. Process Lifecycle

  50. Process Genealogy

More Related