CMSC 421 Operating Systems Lecture Notes (c) 1997 Howard E. Motteler Processes ========== A process is a program (or code) in execution Most OS's can run several processes at the same time Each process has a virtual CPU, registers, and sometimes its own memory, open files, etc. The real CPU is switched between virtual processes, giving each of them chunks of time This switching is called multiprogramming [ pix of 1. timeline of interleaved processes 2. single physical memory 3. multiple virtual memories ] Sorting out this jumping around can be confusing When possible, we think of a set of "sequential processes," running in parallel "Concurrent" simply means in parallel, or at the same time; we will somtimes speak of concurrent processes With all this switching around, a single process will not usually get to run continuously This makes real-time, and time-dependent programming tricky Real-time examples: aircraft control, tone generator Process Creation and Hierarchies --------------------------------- In Unix new processes are created with a fork() Other systems typically have an explicit "create process" sys call In DOS there is a load and execute call, similar to execve(), that simply replaces the current executing process; the DOS shell lives in separate memory Systems with fork() or create-process sys calls can have a hierarchy of processes For unix, all processes are the children of a special process, "init" init --> getty --> login --> shell --> user A process subtree | |--> getty --> login --> shell --> user B process subtree | |--> getty --> login --> shell --> user C process subtree : : Process State -------------- A process can be in one of three states [ pix of three states--running, ready, and blocked--and their transitions ] running - the process is executing on the CPU ready - the process could run but some other process has the cpu (often the ready processes are queued) blocked - waiting on some external event (usually i/o) The scheduler manages transitions between running and ready states The most common scheduler is "round robin", which simply gives each process an equal "slice" of time To suspend and restart processes, the OS must keep track of the entire process state Thus "state" means both running/ready/waiting, and also all the information needed to suspend and restart the process This state info is saved in the "process table" Process Memory Files program counter ptr to exec root dir CPU registers ptr to stack working dir stack pointer ptr to data open files CPU status word user id protection info process state process id etc. message queue process group etc. etc. Interrupts and the process model --------------------------------- Rather thinking about (e.g.) disk interrupts and disk interrupt service routines, we can have devices managed by processes In this scheme, a disk controller is simply a process that waits for either a request message (e.g., get me block 247) a hardware message (e.g., block 247 is ready) This still requires a very simple interrupt handler, to send messages on interrupt This makes organizing the OS much easier, but there is some overhead from the messages Threads -------- Threads are "lightweight" processes that share some process state info Typically, threads will share memory and open files The OS itself may be organized as a set of threads There is less overhead in switching between threads (of a group) than between full processes Do a "man m_fork()" to learn about the SGI threads package