UNIX Process CreationUNIX System ProcessesUNIX Process ImageSlide 4Process CharacteristicsMultithreading vs. Single threadingThreadsSingle Threaded and Multithreaded Process ModelsBenefits of Threads vs ProcessesBenefits of ThreadsApplication benefits of threadsSlide 12Threads StatesUser-Level Threads (ULT)Threads libraryKernel Activity for ULTsAdvantages and inconveniences of ULTKernel-Level Threads (KLT)Advantages and inconveniences of KLTCombined ULT/KLT ApproachesSolarisPowerPoint PresentationSolaris: versatilitySolaris: user-level thread executionSolaris: user-level thread statesDecomposition of user-level Active stateSolaris: Lightweight Process StatesOperating System Control StructuresProcess images in virtual memoryLocation of the Process ImageProcess Control BlockPCB Process IdentificationPCB Processor State InformationPCB Process Control InformationExecution ModesCPU Context SwitchContext Switching Basic StepsProcess SchedulingScheduling QueuesReady and I/O Device QueuesProcess Scheduling Queueing DiagramSchedulersShort-term Scheduler DispatcherLong-term SchedulerThe need for swapping1UNIX Process CreationUNIX Process CreationEvery process, except process 0, is created by the fork() system callfork() allocates entry in process table and assigns a unique PID to the child processChild gets a copy of the parent process image Both child and parent are executing the same code following fork() Need to invoke execve to load new binary filefork() returns the PID of the child to the parent process and returns 0 to the child process2UNIX System ProcessesUNIX System ProcessesProcess 0 is created at boot time and becomes the “swapper” after forking process 1 (the INIT process)When a user logs in, process 1 creates a process for that user3UNIX Process ImageUNIX Process ImageUser-level contextProcess Text (ie: code: read-only)Process DataUser Stack (calls/returns in user mode) Shared memory (for IPC)only one physical copy exists but, with virtual memory, it appears as it is in the process’s address spaceRegister context4UNIX Process ImageUNIX Process ImageSystem-level contextProcess table entry the actual entry concerning this process in the Process Table maintained by OS•Process state, UID, PID, priority, event awaiting, signals sent, pointers to memory holding text, data...U (user) areaadditional process info needed by the kernel when executing in the context of this process•effective UID, timers, limit fields, files in use ...Kernel stack (calls/returns in kernel mode)Per Process Region Table (used by memory manager)5Process CharacteristicsProcess CharacteristicsThe two characteristics are treated independently by some recent OSThe unit of dispatching is usually referred to a thread or a lightweight processThe unit of resource ownership is usually referred to as a process or task6Multithreading vs. Single threadingMultithreading vs. Single threadingMultithreading: when the OS supports multiple threads of execution within a single processSingle threading: when the OS does not recognize the concept of threadMS-DOS support a single user process and a single threadUNIX supports multiple user processes but only supports one thread per processSolaris supports multiple threads7ThreadsThreadsHas an execution state (running, ready, etc.)Context is saved when not runningHas an execution stack and some per-thread static storage for local variablesHas access to the memory address space and resources of its processAll threads of a process share thisWhen one thread alters a (non-private) memory item, all other threads (of the process) sees thatA file opened by one thread, is available to others8Single Threaded and Multithreaded Single Threaded and Multithreaded Process ModelsProcess ModelsThread Control Block contains a register image, thread priority and thread state information9Benefits of Threads vs ProcessesBenefits of Threads vs ProcessesTakes less time to create a new thread than a processLess time to terminate a thread than a processLess time to switch between two threads within the same process10Benefits of ThreadsBenefits of ThreadsClient/Server paradigm Server may need to handle several file requests over a short period of timeMore efficient to create (and destroy) a thread for each requestMultiple threads can execute simultaneously on different processors11Application benefits of threadsApplication benefits of threadsConsider an application that consists of several independent parts that do not need to run in sequenceEach part can be implemented as a threadWhenever one thread is blocked waiting for an I/O, execution could possibly switch to another thread of the same application (instead of switching to another process)12Benefits of ThreadsBenefits of ThreadsSince threads within the same process share memory and files, they can communicate with each other without invoking the kernel Therefore, it becomes necessary to synchronize the activities of various threads so that they do not obtain inconsistent views of the data13Threads StatesThreads StatesThree key states: running, ready, blockedThey have no suspend state because all threads within the same process share the same address spaceIndeed: suspending (ie: swapping) a single thread involves suspending all threads of the same processTermination of a process, terminates all threads within the process14User-Level Threads (ULT)User-Level Threads (ULT)The kernel is not aware of the existence of threadsAll thread management is done by the application, using a thread libraryThread switching does not require kernel mode privileges Scheduling is application specific15Threads libraryThreads libraryContains code for:Creating and destroying threadsPassing messages and data between threadsScheduling thread executionsSaving and restoring thread contexts16Kernel Activity for ULTsKernel Activity for ULTsThe kernel is not aware of thread activity but it is still managing process activityWhen a thread makes a system call, the whole process will be blocked For the thread library that thread is still in the running stateSo thread states are independent of process states17Advantages and inconveniences of ULTAdvantages and inconveniences of ULTAdvantagesThread switching does not involve the kernel: no mode switchingScheduling can
View Full Document