880 likes | 1.26k Views
UNIX Foundations. The Process and the Kernel. Course Description. The Goals for this course Understand UNIX Understand Operating Systems Prerequisites: COSC 2P13 : Introduction to Operating Systems COSC 2P91 : Procedural Programming. Course Description.
E N D
UNIX Foundations The Process and the Kernel
Course Description • The Goals for this course • Understand UNIX • Understand Operating Systems • Prerequisites: • COSC 2P13 : Introduction to Operating Systems • COSC 2P91 : Procedural Programming
Course Description • An intensive study of computer operating system design • Multiprogramming • Time-sharing • Real-time processing • Job and task control • Synchronization of concurrent processes and processors • Resource scheduling • Protection • Management of hierarchical storage.
How to study this course • Read and remember • Read the book, remember the concepts and commands • Think • Think operating systems as natural administrative agents • Practice • Coding with UNIX, use and understand of UNIX commands and get the results
The Textbook Used • Uresh Vahalia, UNIX Internals: The New Frontiers, Prentice Hall, 1996 • Why we use this book? • UNIX is one of the most popular operating systems of the world. • If you understand UNIX, you can understand other operating systems.
References • William Stallings, Operating Systems,5th Ed., Prentice Hall,2005 • A. Tanenbaum, Modern Operating Systems, 2nd ed. Prentice Hall 2001 • Kay A. Robbins and Steven Robbins, UNIX Systems Programming, Prentice Hall,2003 • W. R. Stevens, Advanced Programming in the UNIX Environment, Addison Wesley, 1992
Summary of UNIX History XPG Digital UNIX SVID POSIX Solaris ULTRIX 4.4BSD HP-UX SVR4 4.3BSD SCO UNIX SunOS AIX SVR3 4.2BSD XENIX SVR2 4BSD 3BSD UNIX
V1 . . . V6 Summary of UNIX History Xenix BSD V7 PWB 2BSD . . . 2.9BSD 2.10BSD 2.11BSD PWB2 32V 3BSD 4BSD 4.2BSD 4.3BSD 4.4BSD SIII V8 Xenix2 SYSV V10 SCO V.2 Plan9 Ultrix V.3 SUNOS AIX V.3.2 Mach OSF1 SVR4 Solaris LINUX
Flexibility • Traditional Kernel: file, scheduling, executable file formats
Assessment of UNIX • Advantages: - open software process, - well designed, small and simple kernel, - text files in system databases, - simple, uniform interface to I/O devices, - portability (written in C)
Assessment of UNIX • Disadvantages: - expansion of the more and more complex I/O library, - unfriendly user interface, - building block approach to tools, but not to the kernel, - too many versions and standards, - monolithic, unmodular and more and more complex kernel.
UNIX Architecture • Hardware is surrounded by the operating-system • Operating system is called the kernel • Comes with a number of user services and interfaces • shell • C compiler
Application Programs Shell Editors, and Private User Programs Kernel Compiler Compiler Components Hardware UNIX Architecture
UserInterface The layers of a UNIX system.
UNIX Utility Programs A few of the more common UNIX utility programs required by POSIX
UNIX shell programming • cp src dest • head –20 file • ls *.c • sort <in >out • sort <in >temp;head –30<temp;rm temp • sort <in | head –30 • grep ter *.t | sort | head –20 | tail –5 >foo • sort <x | head &
Process • In UNIX • Process is an instance of a running program. • Lifetime: fork/vfork->exec->exit • Well-defined hierarchy: parent,child,init, • init process: the top process • swapper & pagedeamon • Orphans: the parent process is terminated.
Process Creation • Submission of a batch job • User logs on • Created to provide a service such as printing • Spawned by an existing process
Process Termination • Batch job issues Halt instruction • User logs off • Process executes a service request to terminate • Error and fault conditions
Reasons for Process Termination • Normal completion • Time limit exceeded • Memory unavailable • Bounds violation • Protection error • example write to read-only file • Arithmetic error • Time overrun • process waited longer than a specified maximum for an event
Reasons for Process Termination • I/O failure • Invalid instruction • happens when try to execute data • Privileged instruction • Data misuse • Operating system intervention • such as when deadlock occurs • Parent terminates so child processes terminate • Parent request
Process States • The Running state • The process that gets executed (single CPU) • The Ready state • any process that is ready to be executed • The Blocked state • when a process cannot execute until some event occurs (ex: the completion of an I/O)
Process States • The New state • OS has performed the necessary actions to create the process • has created a process identifier • has created tables needed to manage the process • but has not yet committed to execute the process (not yet admitted) • because resources are limited • The Exit state • Termination moves the process to this state • It is no longer eligible for execution • Tables and other info are temporarily preserved for auxiliary program
Five-State Process Model Dispatch Release Admit New Ready Running Exit Time-out Event Wait Event Occurs Blocked
Single Blocked Queue Ready Queue Release Dispatch Admit Processor Time-out Event Wait Event Occurs Blocked Queue
Event 1 Wait Event 1 Occurs Event 1 Queue Event 2 Wait Event 2 Occurs Event 2 Queue Multiple Blocked Queues Ready Queue Release Dispatch Admit Processor Time-out
Suspended Processes • Processor is faster than I/O so all processes could be waiting for I/O • Swap these processes to disk to free up more memory • Blocked state becomes suspend state when swapped to disk • Two new states • Blocked, suspend • Ready, suspend
Process State Transition Diagram with Two Suspend States Ready Admit Suspend Admit Dispatch Activate Ready, suspend Ready Running Exit Suspend Time out Event Wait Event Occurs Event Occurs Activate Blocked, suspend Blocked
Processor State Information • Contents of processor registers • User-visible registers • Control and status registers • Stack pointers • Program status word (PSW) • contains status information
Process Control Information • Additional information needed by the operating system to control and coordinate the various active processes • scheduling and state information • data structuring • interprocess communication • process privileges • memory management • resource ownership and utilization
Process Creation • Assign a unique process identifier • Allocate space for the process • Initialize process control block • Set up appropriate linkages • Ex: add new process to linked list used for scheduling queue • Other • maintain an accounting file
When to Switch a Process • Interrupts • Clock • process has executed for the maximum allowable time slice • I/O • Memory fault • memory address is in virtual memory so it must be brought into main memory • Trap • error occurred • may cause process to be moved to Exit state • Supervisor call • such as file open
Change of Process State • Save context of processor including program counter and other registers • Update the process control block with the new state and any accounting information • Move process control block to appropriate queue - ready, blocked • Select another process for execution • Update the process control block of the process selected • Update memory-management data structures • Restore context of the selected process
UNIX Process State • Initial (idle) • Ready to run • Kernel/User running • Zombie • Asleep • for 4BSD: stopped/suspend
Process Context • User address space: • code, data, stack, shared memory regions, • Control information: • u area, proc, kernel stack, ATM • Credentials: UID & GID • Environment variables: • inherited from the parent • Hardware context(in PCB of u area): • PC, SP, PSW, MMR, FPU
User Credentials • Superuser: UID=0, GID=1 • Real IDs: log in, send signals • Effective IDs: file creation and access • exec: • suid mode: that of the owner; • sgid mode: that of the calling process • setuid / setgid: • SV & BSD are different with these • saved UID, saved GID in SV • setgroup in BSD
The u Area • part of the process space, needed only when running. • PCB • proc pointer • UID s • Arguments, results, error status from system calls • Signal handlers and related information • Info from the program header, text, data, stack size, MM info • Open file descriptor • Vnodes & controlling terminal pointers • CPU usage statistics, profiling info, disk quotas, & resource limits • Per-process kernel stack
The proc • Process table • Id • Location of the kernel address map for the u area • Current process state • Forward and backward pointers in scheduled queue • Sleep channel (7.2.3) • Scheduling priority and related (Chapter 5) • Signal handling info(Chapter 4). • MM info • Pointers to link active, free, zombie processes in lists • Flags • Pointers to keep structures on a hash queue by PID • Hierarchy info
Process ID A typical process hierarchy in 4.3BSD UNIX Parent Process ID pointer to parent’s proc Pointer to the younger sibling Pointer to the oldest child
Typical Functions of an Operating-System Kernel • Process Management • Process creation and termination • Process scheduling and dispatching • Process switching • Process synchronization and support for inter-process communication • Management of process control blocks • Memory Management • Allocation of address space to processes • Swapping • Page and segment management
Typical Functions of an Operating-System Kernel • I/O Management • Buffer management • Allocation of I/O channels and devices to processes • Support Functions • Interrupt handling • Accounting • Monitoring
Operating System Control Structures • An OS maintains the following tables for managing processes and resources: • Memory tables • I/O tables • File tables • Process tables
Memory Tables • Allocation of main memory to processes • Allocation of secondary memory to processes • Protection attributes for access to shared memory regions • Information needed to manage virtual memory
I/O Tables • I/O device is available or assigned • Status of I/O operation • Location in main memory being used as the source or destination of the I/O transfer
File Tables • Existence of files • Location on secondary memory • Current Status • Attributes • Sometimes this information is maintained by a file-management system
Process Table • Process image consists of program, data, stack, and attributes • Attributes • process control block
Process Control BlockProcess Identification • Unique numeric identifier • may be an index into the primary process table • User identifier • who is responsible for the job