ICS 143 Principles of Operating Systems Discussion Section
CS 143A Discussion TA: Kyle Benson, E-Mail: kebenson@uci.edu TA: Qiuxi Zhu, E-Mail: qiuxiz@ics.uci.edu TA: Joe Nash, E-Mail: jmnash@uci.edu Regarding emails General questions of a non-personal nature should be directed to Piazza forum, NOT email Please add “CS143A” to the subject line for personal/sensitive email questions Office hours: Tuesdays 1:00p-2:30p in DBH 4013 Same time/location each week, different TA/grader. 11/19/2018
Homework #1 Homework #1 out now on class website Due Thursday April 14, 11:55pm via EEE Dropbox This is the submission deadline! Please submit single PDF file No late submissions will be accepted Ask questions on Piazza 11/19/2018
Process =? Program Program Process main () { …; } A() { … main () { …; Heap Stack A main 11/19/2018
Process Process - a program in execution A process contains process execution proceeds in a sequential fashion A process contains program counter, registers Memory: text section, stack, data section and heap Other resources: e.g. opened files Security attributes 11/19/2018
Process State A process changes state as it executes. Process exits when done. Process is admitted to system, has all resources, ready to compete for CPU Maybe process is not done, but interrupt forces it stop new admitted interrupt I/O or event completion Scheduler dispatch event wait exit ready running terminated waiting Process is being created, may have some resources already Process is now running (assigned by scheduler) Event or I/O complete: go back to ready (CPU might not be ready yet) Waiting on I/O or event (trigger for some other process to go from ready to running) 11/19/2018
Process Control Block Process Control Block Contains information associated with each process Process State - e.g. new, ready, running etc. Process Number – Process ID Program Counter - address of next instruction to be executed CPU registers - general purpose registers, stack pointer etc. CPU scheduling information - process priority, pointer Memory Management information - base/limit information Accounting information - time limits, I/O status information 11/19/2018
Context Switching 11/19/2018
Schedulers Long-term scheduler (or job scheduler) - selects which processes should be brought into the ready queue. invoked very infrequently (seconds, minutes); may be slow. controls the degree of multiprogramming Short term scheduler (or CPU scheduler) - selects which process should execute next and allocates CPU. invoked very frequently (milliseconds) - must be very fast Medium Term Scheduler swaps out process temporarily balances load for better throughput 11/19/2018
Process Profiles I/O bound process CPU bound process spends more time in I/O, short CPU bursts, CPU underutilized. CPU bound process spends more time doing computations; few very long CPU bursts, I/O underutilized. The right job mix: Long term scheduler - admits jobs to keep load balanced between I/O and CPU bound processes Medium term scheduler – ensures the right mix (by sometimes swapping out jobs and resuming them later) 11/19/2018
Linux Process Creation fork() creates a copy of the current process exec() can be called after fork() to load a new program to replace the current one 11/19/2018
Threads Processes do not share resources well high context switching overhead A thread (or lightweight process) Basic unit of CPU utilization; it consists of: program counter, register set and stack space A thread shares the following with peer threads: code section, data section and OS resources (open files, signals) Collectively called a task. Heavyweight process is a task with one thread. 11/19/2018
Processes and Threads 11/19/2018
Processes and Threads 11/19/2018
Types of Threads Kernel-supported threads User-level threads Windows NT, Linux, Mac OS X, UNIX, Solaris, … User-level threads POSIX pthreads, Java threads Hybrid approach that implements both 11/19/2018
Kernel Threads Supported by the Kernel Native threads supported directly by the kernel Every thread can run or block independently One process may have several threads waiting on different things Downside of kernel threads: a bit expensive Need to make a crossing into kernel mode to schedule Examples Windows XP/2000, Linux, Tru64 UNIX, Mac OS X, Solaris, Mach, OS/2 11/19/2018
User Threads Supported above the kernel, via a set of library calls at the user level. Thread management done by user-level threads library User program provides scheduler and thread package May have several user threads per kernel thread Advantages Cheap, Fast Threads do not need to call OS and cause interrupts to kernel Disadvantages: If kernel is single threaded, system call from any thread can block the entire task Example thread libraries: POSIX Pthreads, Win32 threads, Java threads 11/19/2018
Multi-? Multiprocessing Multiprogramming Multithreading Multiple CPUs Multiple processes running concurrently Multithreading Multiple threads per process 11/19/2018
Cooperating Processes Concurrent Processes can be Independent processes cannot affect or be affected by the execution of another process. Cooperating processes can affect or be affected by the execution of another process. Advantages of process cooperation: Information sharing Computation speedup Modularity Convenience (e.g. editing, printing, compiling) Concurrent execution requires process communication and process synchronization 11/19/2018
Inter-process Communication Processes have separated address spaces How do processes communicate and synchronize with others? Shared memory Mapping addresses to commonly accessible memory Messaging system send() and receive() messages Can be used over network Can be used simultaneously in a single OS or a single process 11/19/2018