1.03k likes | 3.82k Views
Unix Architecture. Typical computer system consists of: Hardware Operating system Applications and utilities Typical OS includes a user interface or command interpreter Unix is somewhat unique in that the command interpreter is not integrated with the OS but is a separate program.
E N D
Unix Architecture • Typical computer system consists of: • Hardware • Operating system • Applications and utilities • Typical OS includes a user interface or command interpreter • Unix is somewhat unique in that the command interpreter is not integrated with the OS but is a separate program
Levels of Unix Software • Unix uses a layer approach of defining software • Layered approach is basis for Unix security • At the lowest level, the level closest to the hardware, are the basic hardware interface modules • Process scheduling • Memory management • Interrupt handling • Low level device control • Disk system management and data buffering • Process synchronization and inter-process communication (IPC)
Kernel Services Layer • The next level provides all the kernel services • Mapping between user requests and device driver actions • The user system call is converted to a kernel service call that actually performs the requested service • Process creation and termination • I/O services • File/disk access services • Terminal handling services
System Call Interface Layer • The system call interface layer converts a process running in user mode to a protected kernel mode process • This allows the program to invoke protected kernel routines to perform system functions
User Process Layer • The uppermost layer consists of user processes running: • Shells • Unix commands • Utility programs • User application programs • User processes: • Protected from from other users • Have no access to Unix kernel routines except through the system call interface • Cannot directly access kernel memory space
Kernel vs User Space • In addition to the software levels, Unix also features two "rings of protection" from inadvertent programming errors or malicious attacks that might damage other user's processes or the kernel's processes and data structures • The inner protected ring is known as kernel space • The outer ring is called user space
User Space • User space is the area in memory where user processes are run • This consists of memory starting above the kernel and includes the rest of available memory • This memory is protected; the system prevents one user from interfering with another • Only kernel process can access a user process • A process operating in this memory region is said to be operating in user mode
Kernel Space • Kernel space is the region of memory where all kernel services are provided via kernel processes • Any process executing in kernel space is said to be executing in kernel mode • Kernel space is a privileged area; the user has access to it only through the system call interface • A user does not have direct access to either all machine instructions or devices • A kernel process does have direct access to both
Also, a kernel process can modify the memory map, an operation frequently required to perform process scheduling • A user process becomes a kernel process when it executes a system call and starts executing kernel code
Data Flow Between Kernel and User Space • Since users and the kernel do not share memory address space, the mechanism for moving data between them is important • When a system call is executed, the arguments to the call and the corresponding kernel routine identification are passed from user space to kernel space • Kernel routine ID is usually passed either via a hardware machine register or via the stack • System call arguments are passed in the u area (user area) of the calling process
u area of a process (user structure and kernel stack) contains information about the process the kernel needs while the process is running • Open files, root, current directory, arguments to current system call, and process text, stack, and data segment sizes • A pointer to the process table entry containing information for scheduling such as priority • User file descriptor table and information about open files • Kernel stack for the process (empty when executing in user mode) • Remember, user cannot access kernel space but kernel space can access user space
Unix Command Interface and Commands • Unix command interface is a separate program referred to as the shell • The shell provides the user interface between the user and the kernel • Unix commands and utilities, like the shell, are also separate programs • They are part of a Unix distribution, and are considered part of Unix but not part of the kernel
Unix System Services • Unix provides a number of system services such as systems administration, system reconfiguration, and file system maintenance • Other services include • Customization of system parameters • Rebuilding of kernel with user drivers • Creation and definition of user accounts • Set up and maintenance of access control parameters for files and peripherals • Most services are built into the kernel as system calls
Unix System Calls • System calls provide a programming interface that allows user programs to access kernel functions • There are a large number of system calls that perform functions to manage system resources such as memory, disk storage, and peripherals • System calls are defined in a run-time library that provides a mapping of the system call interface to the kernel routine(s) that perform the system functions • The shell also provides functionality equivalent to many of the system calls
System Usage Accounting Services • Unix provides some general accounting services • As each process terminates, an accounting record is made available describing the resources used by the process • Name of the process • Amount of user and system CPU time used • Elapsed (wall clock) time • Average amount of memory used • Number of disk I/O operations done • UID and GID of the process • Terminal from which the process was started
My Best Unix System Programming Book W. Richard Stevens, $65.95