Process Scheduling
Process The activation of a program. Can have multiple processes of a program Entities associated with a process –Instruction pointer, SP, other registers –user who owns it –memory location of user data areas –own run-time stack –instructions Different for each process
Processes Running Solaris (sun) -> ps -Af linux -> ps –aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root ? S Sep21 0:07 init root ? SW Sep21 0:00 [keventd] root ? SW Sep21 0:05 [kapmd] root ? SWN Sep21 0:14 [ksoftirqd_CPU0] root ? SW Sep21 1:06 [kswapd] root ? SW Sep21 0:00 [bdflush] root ? SW Sep21 0:40 [kupdated] root ? SW< Sep21 0:00 [mdrecoveryd] root ? SW Sep21 3:02 [kjournald] root ? S Sep21 0:00 devfsd /dev root ? SW Sep21 0:00 [khubd] root ? SW Sep21 0:23 [kjournald] root ? SW Sep21 1:22 [kjournald] root ? SW Sep21 5:03 [kjournald] root ? S Sep21 0:08 httpd-perl -f /et apache ? S Sep21 0:00 httpd-perl -f /et apache ? S Sep21 0:00 httpd-perl -f /et apache ? S Sep21 0:00 httpd-perl -f /et
Process Scheduling Order of process execution is unpredictable Duration of execution is unpredictable OS and/or hardware can support concurrency Whether there is an appearance or real concurrency is not relevant to the designer. There will generally be a need to resynchronize activity between cooperating processes
Context switch When OS switches running process, it manipulates internal process tables Loading/storing registers must be done Thread s minimize that effort. Same process, but a different run-time stack. A process within a process. Necessary overhead to manage processes but must balance overhead with advantage of concurrency (real or apparent)
What causes context switch? Process runs out of share of CPU time Process blocks –Doing I/O –Waiting on another process to communicate Process terminates
Blocking A process needs to do I/O, transfer disk to memory. Another process can use CPU Conflict ->Bus Running process gets the priority Blocked processes use the cpu when free CPU Memory Disk
Operating Systems Scheduling Ready Running 200 Blocked blocks when reading from the disk Ready Running 205 Blocked Ready Running 205 Blocked unblocks when done, ->ready
What other activities are important in scheduling? Jobs go from RUNNING to READY when they lose their time slot Jobs go from blocked to READY when the I/O operation they are waiting for completes Jobs go from RUNNING to being removed completely upon exit
How does this create concurrency? I/O usage and CPU usage Execute concurrently –CPU is adding –Disk is moving heads and buffering data for transfer across the bus. One of the main efforts of the OS is to manage this concurrency –In addition to lots of others: security, fairness,etc
How do you get limited parallelism from the OS? time Process A runs onCPU; blocks on read Disk reads for B while blocked Disk reads for A while A blocked Process C runs for it’s time slice Process B runs cpu disk controller There are times when both processors (CPU and controller) are busy so real parallelism does occur but not at the level of the CPU
Concurrency at many levels Process level.. –Scheduling the overlap of CPU and I/O –CAN use concurrency if multiple CPUs AND OS supports Subprocess level (like a procedure)..thread –Mini-context switch same main process Different subprocess Statement level –Typically requires special hardware (arrays of cpus)