CS 423 Operating System Design: Systems Programming Review

1y ago
8 Views
2 Downloads
2.96 MB
52 Pages
Last View : 10d ago
Last Download : 3m ago
Upload by : Troy Oden
Transcription

CS 423Operating System Design:Systems ProgrammingReviewProfessor Adam BatesFall 2018CS423: Operating Systems Design

Goals for Today Learning Objectives: Conduct a quick review of systems programmingAnnouncements: C4 readings for Week 2 are out! Due Jan 25 (UTC-11) HW0 is available on Compass! Due Jan 25 (UTC-11) MP0 is available for review on Compass!Due Jan 28 (UTC-11)Reminder: Please put awaydevices at the start of classCS 423: Operating Systems Design2

Goals for Today Announcements continued: TA Office Hours: Monday 3-5pm Room: Siebel Center 0207 Go here for MP questions! Note: No OH on MLK Jr. DayAlberto (TA)Reminder: Please put awaydevices at the start of classCS 423: Operating Systems Design3

SP18 Flashback: Meltdown/Spectre PatchThis is from arch/x86/kernel/cpu/common.c:Architecture-specific code lives in the arch subdirectory,so the patch is definitely architecture-specific!Takeaway? The Linux source tree has an intuitive structureThank David and Yifan for the info!CS423: Operating Systems Design4

System CallsFunction CallsSystem CallsProcessfnCall()?Caller and callee are in the sameProcess- Same user- Same “domain of trust”CS 423: Operating Systems Design5

System CallsFunction CallsSystem CallsProcessProcesssysCall()fnCall()OSCaller and callee are in the sameProcess- Same user- Same “domain of trust”CS 423: Operating Systems Design-OS is trusted; user is not.OS has super-privileges; user does notMust take measures to prevent abuse6

Example System Calls?CS 423: Operating Systems Design7

Example System Calls?Example:getuid() //get the user IDfork()//create a child processexec()//executing a programDon’t confuse system calls with stdlib callsDifferences?Is printf() a system call?Is rand() a system call?CS 423: Operating Systems Design8

Example System Calls?Example:getuid() //get the user IDfork()//create a child processexec()//executing a programDon’t confuse system calls with stdlib callsDifferences?Is printf() a system call?Is rand() a system call?CS 423: Operating Systems Design9

Syscalls vs. I/O Lib CallsEach system call has analogous procedure calls from the standardI/O library:System CallStandard I/O sscanf/printffscanf/fprintffseeklseekCS 423: Operating Systems Design10

Processes Possible process states Running (occupy CPU)BlockedReady (does not occupy CPU)Other states: suspended, terminatedQuestion: in a single processor machine, how many process can be in running state?CS 423: Operating Systems Design11

Processes Possible process states Running (occupy CPU)BlockedReady (does not occupy CPU)Other states: suspended, terminatedQuestion: in a single processor machine, how many process can be in running state?CS 423: Operating Systems Design12

Creating a Process What UNIX call creates a process?CS 423: Operating Systems Design13

Creating a Process - fork() What UNIX call creates a process?fork() duplicates a process so that instead of oneprocess you get two. The new process and the old process both continue inparallel from the statement that follows the fork()CS 423: Operating Systems Design14

Creating a Process - fork() What UNIX call creates a process?fork() duplicates a process so that instead of oneprocess you get two. The new process and the old process both continue inparallel from the statement that follows the fork()How can you tell the two processes apart?CS 423: Operating Systems Design15

Creating a Process - fork() What UNIX call creates a process?fork() duplicates a process so that instead of oneprocess you get two. The new process and the old process both continue inparallel from the statement that follows the fork()How can you tell the two processes apart? fork() returns 0 to child -1 if fork fails Child’s PID to parent processCS 423: Operating Systems Design16

Creating a Process - fork() What UNIX call creates a process?fork() duplicates a process so that instead of oneprocess you get two. The new process and the old process both continue inparallel from the statement that follows the fork()How can you tell the two processes apart? fork() returns 0 to child -1 if fork fails Child’s PID to parent processIf the parent code changes a global variable, will thechild see the change?CS 423: Operating Systems Design17

Creating a Process - fork() What UNIX call creates a process?fork() duplicates a process so that instead of oneprocess you get two. The new process and the old process both continue inparallel from the statement that follows the fork()How can you tell the two processes apart? fork() returns 0 to child -1 if fork fails Child’s PID to parent processIf the parent code changes a global variable, will thechild see the change? Nope! On fork, child gets new program counter, stack, filedescriptors, heap, globals, pid!CS 423: Operating Systems Design18

Creating a Process What if we need the child process to execute differentcode than the parent process?CS 423: Operating Systems Design19

Creating a Process - exec() What if we need the child process to execute differentcode than the parent process? Exec function allows child process to execute code thatis different from that of parent Exec family of functions provides a facility foroverlaying the process image of the calling processwith a new image. Exec functions return -1 and sets errno if unsuccessfulCS 423: Operating Systems Design20

Threads vs. Processes What is the difference between a thread and a process?CS 423: Operating Systems Design21

Threads vs. Processes What is the difference between a thread and a process? Both provided independent execution sequences, but Each process has its own memory space Remember how child processes can’t see changes toparent’s global variable?Threads run in a shared memory spaceCS 423: Operating Systems Design22

Threads vs. Processes What is POSIX?How do you create a POSIX thread?CS 423: Operating Systems Design23

Threads vs. Processes What is POSIX?How do you create a POSIX thread?POSIX functiondescriptionpthread createcreate a threadpthread detach set thread to release resourcespthread equaltest two thread IDs for equalitypthread exitexit a thread without exiting processpthread killsend a signal to a threadpthread joinwait for a threadpthread selffind out own thread IDCS 423: Operating Systems Design24

Threads: Lightweight Proc’sEnvironment (resource) execution(a) Three processes each with one thread(b) One process with three threadsCS 423: Operating Systems Design!2525

Threads: Kernel v. User What is the difference between kerneland user threads? Pros and Cons?CS 423: Operating Systems Design26

Threads: Kernel v. User What is the difference between kerneland user threads? Pros and Cons?Kernel thread packages Each thread can make blocking I/O callsCan run concurrently on multiple processorsThreads in User-level Fast context switchCustomized schedulingCS 423: Operating Systems Design27

Hybrid Threads (Solaris)M:N model multiplexes N user-level threads onto M kernel-level threadsGood idea? Bad Idea?CS 423: Operating Systems Design28

Synchronization Processes and threads can be preempted atarbitrary times, which may generate problems.Example: What is the execution outcome of thefollowing two threads (initially x 0)?Thread 1:Thread 2:Read XAdd 1Write XRead XAdd 1Write XHow do we account for this?CS 423: Operating Systems Design29

Critical Regions/SectionsProcess {while (true) {ENTER CRITICAL SECTIONAccess shared variables;LEAVE CRITICAL SECTIONDo other work}}CS 423: Operating Systems Design30

Mutex Simplest and most efficient thread synchronizationmechanismA special variable that can be either in locked state: a distinguished thread that holds or owns themutex; or unlocked state: no thread holds the mutexWhen several threads compete for a mutex, the losers blockat that call The mutex also has a queue of threads that are waiting tohold the mutex.POSIX does not require that this queue be accessed FIFO.Helpful note — Mutex is short for “Mutual Exclusion”CS 423: Operating Systems Design31

POSIX Mutex Functions int pthread mutex init(pthread mutex t *restrict mutex,const pthread mutexattr t *restrict attr); Also see PTHREAD MUTEX INITIALIZERint pthread mutex destroy(pthread mutex t *mutex);int pthread mutex lock(pthread mutex t *mutex);int pthread mutex trylock(pthread mutex t *mutex);int pthread mutex unlock(pthread mutex t *mutex);CS 423: Operating Systems Design32

SemaphoresPseudocode for a blocking implementation of semaphores:void wait (semaphore t *sp)if (sp- value 0) sp- value--;else { Add this process to sp- list block }void signal (semaphore t *sp)if (sp- list ! NULL) remove a process from sp- list,put it in ready state else sp- value ;CS 423: Operating Systems Design33

SchedulingBasic scheduling algorithms FIFO (FCFS)Shortest job firstRound RobinPriority SchedulingCS 423: Operating Systems Design34

SchedulingBasic scheduling algorithms FIFO (FCFS)Shortest job firstRound RobinPriority SchedulingWhat is an optimal algorithm in the senseof maximizing the number of jobs finished?CS 423: Operating Systems Design35

SchedulingBasic scheduling algorithms FIFO (FCFS)Shortest job firstRound RobinPriority SchedulingWhat is an optimal algorithm in the senseof meeting the most deadlines (of real timetasks)?CS 423: Operating Systems Design36

Scheduling Non-preemptive scheduling: The running process keeps the CPU until itvoluntarily gives up the CPU4 process exitsswitches to blocked state1 and 4 only (no 3)Preemptive scheduling: RunningTerminated13ReadyBlockedThe running process can be interrupted andmust release the CPU (can be forced to giveup CPU)CS 423: Operating Systems Design37

Signals What is a signal in UNIX/Linux?CS 423: Operating Systems Design38

Signals What is a signal in UNIX/Linux? A way for one process to send a notification to anotherA signal can be “caught”, “ignored”, or “blocked”CS 423: Operating Systems Design39

Signals What is a signal in UNIX/Linux? A way for one process to send a notification to anotherA signal can be “caught”, “ignored”, or “blocked”Signal is generated when the event that causes it occurs.Signal is delivered when a process receives it.The lifetime of a signal is the interval between its generationand delivery.Signal that is generated but not delivered is pending.Process catches signal if it executes a signal handler when thesignal is delivered.Alternatively, a process can ignore a signal when it is delivered,that is to take no action.Process can temporarily prevent signal from being delivered byblocking it.Signal Mask contains the set of signals currently blocked.CS 423: Operating Systems Design40

POSIX-required Signals*SignalDescriptiondefault actionSIGABRTprocess abortimplementation dependentSIGALRMalarm clockabnormal terminationSIGBUSaccess undefined part of memory objectimplementation dependentSIGCHLDchild terminated, stopped or continuedignoreSIGILLinvalid hardware instructionimplementation dependentSIGINTinteractive attention signal (usually ctrl- abnormal terminationC)SIGKILLterminated (cannot be caught orignored)abnormal termination* Not an exhaustive listCS 423: Operating Systems Design41

POSIX-required Signals*SignalDescriptiondefault actionSIGSEGVInvalid memory referenceimplementationdependentSIGSTOPExecution stoppedstopSIGTERMterminationAbnormal terminationSIGTSTPTerminal stopstopSIGTTINBackground process attempting readstopSIGTTOUBackground process attempting writestopSIGURGHigh bandwidth data available onsocketignoreSIGUSR1User-defined signal 1abnormal termination* Not an exhaustive listCS 423: Operating Systems Design42

User- generated Signals How can you send a signal to a process from thecommand line?CS 423: Operating Systems Design43

User- generated Signals How can you send a signal to a process from thecommand line?killCS 423: Operating Systems Design44

User- generated Signals How can you send a signal to a process from thecommand line?killkill -l will list the signals the system understandskill [-signal] pid will send a signal to a process. The optional argument may be a name or a number(default is SIGTERM).To unconditionally kill a process, use: kill -9 pidwhich iskill -SIGKILL pid.CS 423: Operating Systems Design45

Signal Masks A process can temporarily prevent a signal from being deliveredby blocking it.Signal Mask contains a set of signals currently blocked.Important! Blocking a signal is different from ignoring signal.Why?CS 423: Operating Systems Design46

Signal Masks A process can temporarily prevent a signal from being deliveredby blocking it.Signal Mask contains a set of signals currently blocked.Important! Blocking a signal is different from ignoring signal.Why?When a process blocks a signal, the OS does not deliver signaluntil the process unblocks the signal A blocked signal is not delivered to a process until it is unblocked.When a process ignores signal, signal is delivered and theprocess handles it by throwing it away.CS 423: Operating Systems Design47

DeadlocksCS 423: Operating Systems Design48

DeadlocksWhen do deadlocks occur (hint: 4 preconditions)?CS 423: Operating Systems Design49

DeadlocksWhen do deadlocks occur (hint: 4 preconditions)? CS 423: Operating Systems DesignMutual exclusionHold and wait conditionNo preemption conditionCircular wait condition50

DeadlocksResource Allocation Graphsassignrequest CS 423: Operating Systems Designresource R assigned to process Aprocess B is requesting/waiting for resource Sprocess C and D are in deadlock over resources T and U51

DeadlocksStrategies for Dealing with Deadlocks shouting detection and recovery dynamic avoidance (at run-time) prevention (by offline design)by negating one of the four necessary conditions CS 423: Operating Systems Design52

CS 423: Operating Systems Design 2 Learning Objectives: Conduct a quick review of systems programming Announcements: C4 readings for Week 2 are out!Due Jan 25 (UTC-11) HW0 is available on Compass!Due Jan 25 (UTC-11) MP0 is available for review on Compass! Due Jan 28 (UTC-11) Goals for Today Reminder: Please put away devices at the start of class

Related Documents:

423.1 Slope: Public educational . facilities 10 . 423.2 Public schools and Florida colleges . . 423.4.6 ANSI Z53.1 . 423.4.7 ASCE 7 . 423.4.8 Life cycle cost guidelines for . materials and buildings for . Florida public educational . facilities . 423.5 Definitions 12 .

Tishomingo County Department of Human Services 662-423-7060 Child Support Enforcement 662-423-7020 Economic Assistance 662-423-7041 Family & hildren's Services Tishomingo County Emergency Mgmt & Floodplain Mgmt 662-423-7028 Tishomingo County Health Department 662-423-6100 Tishomingo County High School 662-423-7300

1140 Hidden Valley Dr. Jonesborough, TN 37659 (423) 913-2299 immok@earthlink.net (Mike) See Morganstern Knight Don, Barbara 41 Olivia Lee Court Jonesborough, TN 37659 (423) 788-0233 (423) 767-6020 (Don) bgk11846@gmail.com Koenig Carol, Peter 37 Vesta Sue Court Jonesborough, TN 37659 (423) 426-3730 (423) 426-3255 45pakoenig@gmail.com (Peter)

423.566, 423.580, and 423.600, and obtained at a network pharmacy or an out-of-network pharmacy in accordance with 42 CFR § 423.124. For the applicable drugs of

DOCUMENT RESUME. ED 315 423 TM 014 423. AUTHOR Facione, Peter A. TITLE. . While not synonymous with good thinking, CT is a pervasive and self-rectifying human phenomenon. . names. of their auth l s removed. The exp

2 bizhub 423/363/283/223 Konica Minolta has developed a multifunction device with the user in mind. The bizhub 423/363/283/223 cuts your costs of ownership and reduces your impact on the environment while you do business. Plus the new bizhub 423/363/283/223 black-and-white multifunction device boasts

Guitar Chuckrow, Robert C 423-821-6466 Coulter, Monte 423-344-2677 Monte-Coulter@utc.edu Crum, Marty 615-643-2006 martyworld@comcast.net Eldridge, Lon 423-463-1371 lonmower4@hotmail.com www.LonEldridge.com Hackett, Ronald 931-438-3298 ron@ronhackettmusic.com Horner, Thomas 706-965-6585 tomandeve@charter.net

Konica Minolta bizhub 423/363/283/223 Specification & Installation Guide Copy continued Copy Productivity 1:1 Copy Speed: 8.5" x 11" (Letter) (ppm) bizhub 423 bizhub 363 bizhub 283 bizhub 223 Plain Paper 42 36 28 22 Thick Paper 13 12.5 10 9 Sort/Staple (Simplex): 8.5" x 11" (Letter) (ppm) bizhub 423 bizhub 363 bizhub 283 bizhub 223 Plain Paper .