Overview of UNIX
Course Organization (This lecture is in red) Part I: Unix System Programming (Device Driver Development) Part II: Compiler Design Character Device Driver Development (HW #2) Introduction to Block Device Driver Syntax Analysis (HW #4) Overview of Device Driver Development Lexical Analysis (HW #3) Process & File (HW #1) Overview of Complier Design Overview of Unix Sys. Prog. Overview of the Subject (COMP 3438)
Topics Introduction to system software Unix System programming UNIX programming basics Unix file system and processes Unix device driver development Principles of compiler construction Syntax and semantics of programming languages Lexical analysis Syntax analysis Code generation and optimization
What is Unix? UNIX is a family of general purpose operating systems (OS) Originally developed at AT&T Bell Laboratories. Can be easily adapted to run on different computers - has been available on a wide range of hardware UNIX has become a key part of technology landscape. A huge number of large-scale data management and transaction-processing systems, computer aided design, manufacturing control systems, laboratory simulations are built on UNIX platforms UNIX is the core of the server backbone of the Internet - the Internet itself began life with UNIX. Today, without UNIX systems, the Internet would come to a screeching halt. Most telephone calls could not be made, electronic commerce would grind to a halt
What makes up Unix? UNIX is more than an OS - it also contains other components
Interrupt and Error Handling Unix kernel The kernel is the core of the UNIX OS controls the hardware and performs various low-level functions; A collection of software modules that run in privilege mode (full access to system resources) Other parts of the UNIX system, as well as user programs, request the kernel for various services through system calls . A system call is an entry point directly into the kernel. Unix OS File Management and Security Device Management; Interrupt and Error Handling Date and Time Services System Accounting UNIX System Kernel Process Scheduling & Management Memory Management Inter-Process Communication
Making use of system calls and library functions Programs request UNIX OS kernel services by invoking an appropriate system call. Programs may also utilize many general-purpose C library functions Distinction between system calls and library functions? Both are routines that can be invoked by a user program. Library functions may or may not invoke system calls. System calls run in kernel mode, while library functions run within user’s space.
Unix utilities UNIX also encompasses a broad set of commands, called utilities An environment for software development, text processing, communication, accounting, language processors, databases, etc. Not part of the OS kernel, but a host of supporting programs provided along with the OS. Using UNIX utilities, other system/application programs can be developed - once installed on a UNIX system, these programs are indistinguishable from UNIX utility commands. Utility programs are accessed through the Shell
Unix shell The shell is the powerful command interpreter for UNIX - accepts user commands and is responsible for seeing that they are carried out. The shell itself is a command that acts as an interface between the user and the OS kernel. Each user has a separate shell program, so UNIX handles several shells concurrently.
Hardware Interfaces (Device Drivers) y s t e m o f w a r T o o l s Shell File system Compilers & Libraries Databases Editors Document processing System Call Interface OS Network Extensions OS Kernel Other Extensions Hardware Interfaces (Device Drivers) The hardware interfaces are the only parts of the OS which are machine dependent. They connect the machine-independent parts above them to the specific hardware details and support the use of these machine-independent parts on many different hardware machines - this makes it possible to easily re-implement the OS on different hardware architectures.
Features of Unix Portability Multi-user Operation Multitasking Processing Hierarchical File System Powerful Shell Pipes Networking Robustness In UNIX, several people could be using the computer at the same time. It appears to each user that the computer is executing instructions solely on his or her behalf. The ability of a single computer with a single CPU to execute several programs simultaneously is known as multiprogramming. The computer system executes , perhaps, several thousand instructions of one user’s program, then suspend execution of that program and switches to another user’s program. By regularly switching from one user to another (called time-slicing), each user has the illusion that his or her program is continuously executing. As more users sign on to the system, programs receive time slices less often and the illusion of continuous execution may begin to break down. The UNIX system actually allows each user to have several simultaneously executing programs. There are two ways: 1) Use the shell command language: start up the first program as a background job, and then issue the second program 2) including the fork system function call inside a C program
Unix is portable The UNIX system, as well as the software written for UNIX, is portable to many different machine architectures. UNIX has been installed on many kinds of computers from different vendors. This is due its hierarchical and modular structure, and also its use of the C programming language. In UNIX, several people could be using the computer at the same time. It appears to each user that the computer is executing instructions solely on his or her behalf. The ability of a single computer with a single CPU to execute several programs simultaneously is known as multiprogramming. The computer system executes , perhaps, several thousand instructions of one user’s program, then suspend execution of that program and switches to another user’s program. By regularly switching from one user to another (called time-slicing), each user has the illusion that his or her program is continuously executing. As more users sign on to the system, programs receive time slices less often and the illusion of continuous execution may begin to break down. The UNIX system actually allows each user to have several simultaneously executing programs. There are two ways: 1) Use the shell command language: start up the first program as a background job, and then issue the second program 2) including the fork system function call inside a C program
Unix supports multi users UNIX is a multi-user system- several people could be using the computer at the same time. Uses "time-sharing " maintains a "queue” of tasks waiting to be done and shares the available CPU time among these tasks by assigning time quantum to them. Allows efficient sharing of resources, while offering the security and protection features needed to insulate each user from the activities of other users. In UNIX, several people could be using the computer at the same time. It appears to each user that the computer is executing instructions solely on his or her behalf. The ability of a single computer with a single CPU to execute several programs simultaneously is known as multiprogramming. The computer system executes , perhaps, several thousand instructions of one user’s program, then suspend execution of that program and switches to another user’s program. By regularly switching from one user to another (called time-slicing), each user has the illusion that his or her program is continuously executing. As more users sign on to the system, programs receive time slices less often and the illusion of continuous execution may begin to break down. The UNIX system actually allows each user to have several simultaneously executing programs. There are two ways: 1) Use the shell command language: start up the first program as a background job, and then issue the second program 2) including the fork system function call inside a C program
Unix supports multi-tasking UNIX is a multitasking system - even for a single user, time-sharing still goes on. First, UNIX has some programs, such as system-wide accounting programs, that automatically run from time to time. Second, UNIX supports background processing, which allows a user to initiate a task "in the background" and then proceed to other activities. So, UNIX time-shares between the immediate command and background jobs. Third, UNIX allows the creation of new tasks in a program by including appropriate function calls.
Unix has a hierarchical file system UNIX files are organized into separate directories Directories are themselves organized into a tree-like structure. There is one master directory, called the root directory, from which various sub-directories branch off. The hierarchical structure offers a maximum flexibility for grouping information in a way that reflects its natural structure. A single user's data may be grouped by activity; Data from many different users can be grouped according to corporate organization. As a result, stored data is easier to locate and manage.
Unix shell is powerful The shell supports a number of convenient features, such as redirection of application input and output, e.g. % ls > myfiles the ability to manipulate groups of files with a single command. executing a sequence of commands stored in a text file, called a "shell script", allowing us to build our own commands which may be parameterized. being used as a programming language that provides string-valued variables and control flow primitives including branching and iteration.
Unix’s pipe is novel One of the most famous UNIX features A pipe passes the standard output of one command directly to another command, to be used as its standard input. % who | sort Allows any number of commands to be connected in a sequence, and automatically handles the data flow from one program to the next % who | sort | lp Produces the same effect as if one large program, rather than several small ones, had been executed. allowing the combination of several simple programs to perform more complex functions eliminating the need for new software development.
Unix supports networking Networking support is built into the UNIX system Supports TCP/IP protocols, and provides a new OS abstraction, the socket, that allows application-level programs to access the Internet. The socket abstraction acts as an interface between application level programs and the underlying TCP/IP protocols.
Unix is robust When encounter an error, a UNIX program does not abort. Instead, the program returns a value indicating an error condition, and it is up to the program to check for the error and handle it. Typically, a return error value is negative if the return type is int, or a NULL if the return type is a pointer. The C library function perror() outputs a message string to standard error file followed by the error message from the last system or library call that produced an error
/* Example */ The open system call #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int fd; if ((fd = open("my.file", O_RDONLY)) == -1) perror("Unsuccessful open of my.file"); The following output might be produced if my.file does not exist Unsuccessful open of my.file: No such file or directory
History of Unix Two major families of UNIX implementations: System V : evolved from the original AT&T UNIX. BSD (Berkeley Software Distributions) UNIX Both are merging now
System V - had gone through 10 The very first version of UNIX Developed at AT&T Bell Lab in 1969 by Ken Thompson. Later, Dennis Ritchie joined and he invented the C language in which later versions of UNIX are written. - had gone through 10 editions now System V was released from AT&T (Western Electric) in 1983 as a standard, and since then has gone through several releases, including V2.2, V3, V3.1, V3.2. V4 (latest release by USL)
BSD Unix First developed by a graduate student, Bill Joy, in 1977 at the University of California at Berkeley, with the goal of providing an open system with sophisticated networking support. Has gone through several versions, including 4.1 BSD, 4.2 BSD, 4.3 BSD, etc. Provides a powerful text editor, called vi, a shell especially suited for C programming, called csh; Focused on file system performance and networking.
SunOs / Solaris, AIX, HP-UX, … SunOS / Solaris (Sun Microsystems) are originally a derivative of BSD UNIX 4.2 and 4.3 More recently based on System V The dominant UNIX OS in the workstation market. IBM’s AIX HP’s HP-UX … FreeBSD Linux
Android (based on Linux) A good website for beginners: http://www.ece.ncsu.edu/wireless/MadeInWALAN/AndroidTutorial/index.html
Mac OS x and iOS (Mach/BSD Linux)
Unix standards The system level differences in the Unix OS produced by various vendors is confusing need a standardization. Standards are established because a consensus arises among vendors and customers about some products (for portability, interoperability, joint-development) Intended to ensure that any device / software can communicate with another device or software through conformance to an interface The standard defines this interface - but doesn't specify exactly how the device or software itself is written. Don't confuse the standard and the product!
Unix standards (cont’d) Three important standards in UNIX-related fields – ANSI C, POSIX, and Spec 1170 used in the textbook. ANSI C is an official standard for C by the ANSI and ISO. POSIX is a collection of official standards for OS interfaces by IEEE - also called IEEE Std. 1003 Spec 1170 is an emerging industrial standard for Unix by X/Open Foundation (later merged with The Open Group) American National Standards Institute (ANSI) International Standards Organization (ISO) International Standards Organization (ISO). POSIX stands for portable OS interface which specifies the interface between the OS and the user in a standard way so that application programs are portable across platforms. Spec 1170 is an emerging industrial standard for Unix by X/Open Foundation (initially formed by several European computer vendors and later becomes an international organization) more comprehensive and covering the entire application environment; incorporating several key standards such as POSIX 1003.1 and X Window system. used in the textbook for items such as networking services, which are not covered by a POSIX standard.
Links to Unix resources For UNIX history and standardization, see http://www.UNIX-systems.org/ For people and stories about UNIX and its descendants, see http://perso.wanadoo.fr/levenez/unix http://www.bell-labs.com/history/unix http://cm.bell-labs.com/cm/cs/who/dmr/cacm.html Do it for fun! - find out who owns the license of UNIX now