Processes_A_ System_View - Concurrency &...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of State Transitions. Impossible Transitions. Zombies and Orphans Copyright : University of Il inois CS 241 Staff Processes - A System View How does fork work? Parent mypid = 4, myppid = 1 int forked_pid , wait_pid; int status = 0; if (forked_pid = fork()) { /* parent */ .. wait_pid = wait(&status); } else { /* child */ .. exit(status); } Child mypid = 6, myppid = 4 int forked_pid, wait_pid; int status = 0; if (forked_pid = fork()) { /* parent */ .. wait_pid = wait(&status); } else { /* child */ .. exit(status); } Copyright : University of Il inois CS 241 Staff How does fork really work? Parent mypid = 4, myppid = 1 int forked_pid , wait_pid; int status = 0; if (forked_pid = fork()) { /* parent */ .. wait_pid = wait(&status); } else { /* child */ .. exit(status); } Child mypid = 6, myppid = 4 int forked_pid , wait_pid; int status = 0; Copyright : University of Il inois CS 241 Staff What the fork? Concurrency What is a sequential program? A single thread of control that executes one instruction When it is finished, it executes the next logical instruction What is a concurrent program? A collection of autonomous sequential programs, executing (logically) in parallel What does this gain us? The appearance that multiple actions are occurring at the same time Copyright : University of Il inois CS 241 Staff What is fork good for? #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { pid_t pid; int i; if(pid = fork()) { /* parent */ } else { /* child */ } return 0; } Copyright : University of Il inois CS 241 Staff childProcedures(); parentProcedures(); What is fork good for? #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { pid_t pid; int i; while (1) { if(pid = fork()) { /* parent */ } else { /* child */ } } return 0; } Copyright : University of Il inois CS 241 Staff /* wait for new clients */ /* handle new client */ /* reset server */ Why Concurrency? Natural Application Structure The world is not sequential! Easier to program multiple independent and concurrent activities Better resource utilization Resources unused by one application can be used by the others Better average response time No need to wait for other applications to complete Copyright : University of Il inois CS 241 Staff Benefits of Concurrency Copyright : University of Il inois CS 241 Staff Keyboard CPU Disk Time Keyboard CPU Disk...
View Full Document

Page1 / 8

Processes_A_ System_View - Concurrency &...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online