DOC PREVIEW
U of I CS 241 - Scheduling & Signals

This preview shows page 1-2-3-20-21-40-41-42 out of 42 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS241 Systems ProgrammingDiscussion week 5: Scheduling & Signals2/19/07 – 2/23/07Stephen KloderCPU SchedulingThe CPU Scheduler decides which thread should be in the running state.It is called when:–A new thread is created–A thread finishes–A clock interrupt occurs–An I/O interrupt occurs–A thread yieldsAlgorithms•First-Come First-Serve (FCFS)•Shortest Job First (SJF)•Priority•Round Robin (RR)CPU SchedulingScheduling algorithms can be preemptive or non-preemptiveNon-Preemptive: Each thread chooses when to yield the processor•system call•thread finishesPreemptive: The scheduler can force the thread to yield•time quantum expires•other thread preempts current oneMetricsResponse TimeThe time from the submission of a thread until the thread begins to executeWaiting TimeTotal time that a thread spends waitingTurnaround TimeThread finish time – thread entry timeFirst Come First Serve (FCFS)At t=0, P1 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P2FCFS ExampleAt t=6, P1 finishes, and P2 starts06P1037P3214Priority #06P1Arrival TimeDurationProcess03P408P2FCFS ExampleAt t=14, P2 finishes, and P3 starts06P114P2037P3214Priority #06P1Arrival TimeDurationProcess03P408P2FCFS ExampleAt t=21, P3 finishes, and P4 starts06P114P321P2037P3214Priority #06P1Arrival TimeDurationProcess03P408P2FCFS ExampleAt t=24, P4 finishes06P4P114P321P224037P3214Priority #06P1Arrival TimeDurationProcess03P408P2Metrics for FCFS ExampleP1 waiting time: 0P2 waiting time: 6P3 waiting time: 14P4 waiting time: 21Average response time (ART): (0+6+14+21)/4 = 10.25Average waiting time (AWT): (0+6+14+21)/4 = 10.25Average turnaround time (ATT):(6+14+21+24)/4 = 16.25P1 turnaround time: 6P2 turnaround time: 14P3 turnaround time: 21P4 turnaround time: 2406P4P114P321P224Shortest Job First (SJF)At t=0, P4 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P2SJF ExampleAt t=3, P4 finishes, and P1 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P20 3P4SJF ExampleAt t=9, P1 finishes, and P3 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P20 3P4 P19SJF ExampleAt t=16, P3 finishes, and P2 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P20 3P4 P19P316SJF ExampleAt t=24, P2 finishes037P3214Priority #06P1Arrival TimeDurationProcess03P408P20 3P4 P19P316P224Metrics for SJF ExampleP4 waiting time: 0P1 waiting time: 3P3 waiting time: 9P2 waiting time: 16Average response time (ART): (0+3+9+16)/4 = 7Average waiting time (AWT): (0+3+9+16)/4 = 7Average turnaround time (ATT):(3+9+16+24)/4 = 13P4 turnaround time: 3P1 turnaround time: 9P3 turnaround time: 16P2 turnaround time: 240 3P4 P19P316P224Priority Scheduling ExampleAt t=0, P2 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P2Priority Scheduling ExampleAt t=8, P2 finishes, and P4 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P208P2Priority Scheduling ExampleAt t=11, P4 finishes, and P3 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P208P411P2Priority Scheduling ExampleAt t=18, P3 finishes, and P1 starts037P3214Priority #06P1Arrival TimeDurationProcess03P408P208P411P318P2Priority Scheduling ExampleAt t=24, P1 finishes037P3214Priority #06P1Arrival TimeDurationProcess03P408P208P4 P111P318P224Metrics for Priority Example08P4 P111P318P2 waiting time: 0P4 waiting time: 8P3 waiting time: 11P1 waiting time: 18Average response time (ART): (0+8+11+18)/4 = 9.25Average waiting time (AWT): (0+8+11+18)/4 = 9.25Average turnaround time (ATT):(8+11+18+24)/4 = 15.25P224P2 turnaround time: 8P4 turnaround time: 11P3 turnaround time: 18P1 turnaround time: 24Round Robin ExampleEach thread runs for 1 second, and then yields to the next thread.037P3214Priority #06P1Arrival TimeDurationProcess03P408P20P1 P2 P3 P4Round Robin ExampleAt t=12, P4 finishes (P1, P2, and P3 left in queue)037P3214Priority #06P1Arrival TimeDurationProcess03P408P2012P1 P2 P3 P4Round Robin ExampleAt t=19, P1 finishes (P2 and P3 left in queue)037P3214Priority #06P1Arrival TimeDurationProcess03P408P2012P1 P2 P3 P419Round Robin ExampleAt t=23, P3 finishes (P2 left in queue)037P3214Priority #06P1Arrival TimeDurationProcess03P408P2012P1 P2 P3 P41923Round Robin ExampleAt t=24, P2 finishes037P3214Priority #06P1Arrival TimeDurationProcess03P408P2012P1 P2 P3 P41924Metrics for Round Robin ExampleP1 waiting time: 13P2 waiting time: 16P3 waiting time: 16P4 waiting time: 9Average response time (ART): (0 + 1 + 2 + 3) / 4 = 1.5Average waiting time (AWT): (13+16+16+9)/4 = 13.5Average turnaround time (ATT): (12+24+23+12)/4 = 17.75012P1 P2 P3 P41924P1 turnaround time: 19P2 turnaround time: 24P3 turnaround time: 23P4 turnaround time: 12Method ART AWT ATTFCFS 10.25 10.25 16.25SJF 7 7 13Priority 9.25 9.25 15.25RR 1.5 13.5 17.75Comparison of MetricsSignalsA signal is a software notification to a process of an event.Signals are asynchronous, so the process can handle them no matter where it is in the program.User-triggered signalsCtrl+C triggers SIGINTCtrl+Z triggers SIGSTOPCtrl+D triggers SIGQUITetc.Run stty -a to see others.Sending signals from the command lineThe Unix kill command sends signals. The usage iskill -<signal> <pid>Run kill -l to see available signals.The command is called kill because in many cases the default behavior is for the process receiving the signal to die.Sending signals from inside the programUse the kill() function to send signals from one process to another.#include <sys/types.h>#include <signal.h>int kill(pid_t pid, int sig);Examples:–kill(getpid(),SIGTERM);–kill(getppid(),SIGKILL);Example: ds5-p1.cThis example takes in input one character at a time, and shifts the letters forward by one.Run this program, and send it signals using:–Ctrl+C, Ctrl+Z, etc.–The kill command, from another windowSignal blockingWe can block some signals, so they don’t reach the process right away.ds5-p2.c contains code for blocking SIGINT. The calls used are:sigemptyset(&newsigset);sigaddset(&newsigset,SIGINT);sigprocmask(SIG_BLOCK,&newsigset,NULL);ds5-p2.cRun this program. Note that unlike ds5-p1.c , this program does not respond to Ctrl+C. You will need to send it a SIGKILL signal to kill it.This is because the SIGINT signal has been blocked.(Note: some signals, such as SIGKILL, cannot be blocked.)Signal setsA sigset_t is a set of signals, represented as a bit array. The functions sigemptyset, sigfillset, sigaddset, and sigdelset set and change the signal set.Signal MaskThe


View Full Document

U of I CS 241 - Scheduling & Signals

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Scheduling & Signals
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Scheduling & Signals and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Scheduling & Signals 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?