Implementing Processes, Threads, and Resources

Implementing Processes, Threads, and Resources

Slide 9-1 Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-2 High Level Synchronization and Interprocess Communication Copyright 2004 Pearson Education, Inc. 9 Operating Systems: A Modern Perspective, Chapter 9 Large Amount of Work to Do Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9

Slide 9-3 Partition the Work Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-4 Slide 9-5 Define Dependencies 1B 1B 1A 1A 22 3A 3A

Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 3B 3B Slide 9-6 Assign Work to Threads Thread Thread Thread Thread 1A 1A 1B 1B 22

3A 3A Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 3B 3B Synchronize Thread Execution Thread Thread Thread Thread 1A 1A Synchronization Mechanism Copyright 2004 Pearson Education, Inc.

1B 1B 22 3A 3A Operating Systems: A Modern Perspective, Chapter 9 3B 3B Slide 9-7 The Dining Philosophers Quiz: Write a synchronization schema for the problem Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-8

First Try Solution philosopher(int i) { while(TRUE) { // Think // Eat P(fork[i]); P(fork[(i+1) mod 5]); eat(); V(fork[(i+1) mod 5]); V(fork[i]); } } semaphore fork[5] = (1,1,1,1,1); fork(philosopher, 1, 0); fork(philosopher, 1, 1); fork(philosopher, 1, 2); fork(philosopher, 1, 3); fork(philosopher, 1, 4); Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-9

Slide 9-10 One Answer to the Quiz philosopher(int i) { while(TRUE) { // Think // Eat j = i % 2; P(fork[(i+j) mod 5]); P(fork[(i+1-j) mod 5]); eat(); V(fork[(i+1-j) mod 5]); V(fork[[(i+j) mod 5]); } } semaphore fork[5] = (1,1,1,1,1); fork(philosopher, 1, 0); fork(philosopher, 1, 1); fork(philosopher, 1, 2); fork(philosopher, 1, 3); fork(philosopher, 1, 4); Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Nesting Semaphore Operations pr P Operation Order P(mutex1); P(mutex2); ; ; V(mutex2); V(mutex1); (a) Copyright 2004 Pearson Education, Inc. ps P Operation Order P(mutex2); P(mutex1); ; ; V(mutex1); V(mutex2); (b) Operating Systems: A Modern Perspective, Chapter 9

Slide 9-11 Abstracting Semaphores Relatively simple problems, such as the dining philosophers problem, can be very difficult to solve Look for abstractions to simplify solutions AND synchronization Events Monitors there are others ... Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-12

AND Synchronization Slide 9-13 Given two resources, R1 and R2 Some processes access R1, some R2, some both in the same critical section Need to avoid deadlock due to ordering of P operations Psimultaneous(S1, , Sn) Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Simultaneous Semaphores Def Slide 9-14 P_sim(semaphore S, int N) { L1: if ((S[0]>=1)&& &&(S[N-1]>=1)) { for(i=0; i

where S[i]<1; The calling thread is blocked while it is in the queue; // When the thread is removed from the queue Goto L1; } V_sim(semaphore S, int N) { } for(i=0; i

Semaphore mutex = 1; P_sim(PID callingThread, semaphore R, semaphore S) { L1: P(mutex); if(R.val>0)&&(S.val>0)) { P(R); P(S); V(mutex); } else { if(R.val==0) { V_sim(semaphore R, semaphore S) { R_num++; enqueue(callingThread, R_wait); P(mutex); V(R); V(S); V(mutex); if(R_num>0) { goto L1; R_num--; } else { dequeue(R_wait); // Release a thread S_num++; enqueue(CallingThread, S_wait); } if(S_num>0) { V(mutex); S_num--; goto L1;

dequeue(S_wait); // Release a thread } } } V(mutex); } } Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-16 Dining Philosophers Problem philosopher(int i) { while(TRUE) { // Think // Eat Psim(fork[i], fork [(i+1) mod 5]); eat(); Vsim(fork[i], fork [(i+1) mod 5]); } }

semaphore fork[5] = (1,1,1,1,1); fork(philosopher, 1, 0); fork(philosopher, 1, 1); fork(philosopher, 1, 2); fork(philosopher, 1, 3); fork(philosopher, 1, 4); Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Events Slide 9-17 Exact definition is specific to each OS A process can wait on an event until another process signals the event Have event descriptor (event control block) Active approach Multiple processes can wait on an event Exactly one process is unblocked when a signal occurs A signal with no waiting process is ignored

May have a queue function that returns number of processes waiting on the event Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Example Slide 9-18 class Event { public: void signal(); void wait() int queue(); } shared Event topOfHour; . . . // Wait until the top of the hour before proceding topOfHour.wait(); // Its the top of the hour ...

1 wait() 3 Resume topOfHour topOfHour 2 signal() Copyright 2004 Pearson Education, Inc. shared Event topOfHour; . . . while(TRUE) if(isTopOfHour()) while(topOfHour.queue() > 0) topOfHour.signal(); } . . . Operating Systems: A Modern Perspective, Chapter 9

UNIX Signals Slide 9-19 A UNIX signal corresponds to an event It is raised by one process (or hardware) to call another processs attention to an event It can be caught (or ignored) by the subject process Justification for including signals was for the OS to inform a user process of an event User pressed delete key Program tried to divide by zero Attempt to write to a nonexistent pipe etc. Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 More on Signals Each version of UNIX has a fixed set of signals (Linux has 31 of them) signal.h defines the signals in the OS App programs can use SIGUSR1 & SIGUSR2 for arbitrary signalling Raise a signal with kill(pid, signal) Process can let default handler catch the signal, catch the signal with own code, or cause it to be ignored Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-20 More on Signals (cont) OS signal system call To ignore: signal(SIG#, SIG_IGN) To reinstate default: signal(SIG#, SIG_DFL) To catch: signal(SIG#, myHandler)

Provides a facility for writing your own event handlers in the style of interrupt handlers Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-21 Slide 9-22 Signal Handling /* code for process p */ . . . signal(SIG#, myHndlr); . . . /* ARBITRARY CODE */ Copyright 2004 Pearson Education, Inc. void myHndlr(...) { /* ARBITRARY CODE */

} Operating Systems: A Modern Perspective, Chapter 9 Signal Handling /* code for process p */ . . . signal(SIG#, sig_hndlr); . . . /* ARBITRARY CODE */ Slide 9-23 void sig_hndlr(...) { /* ARBITRARY CODE */ } An executing process, q Raise SIG# for p q is blocked runs in ps address space sig_hndlr

q resumes execution Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Using UNIX Signals Pis Address Space Pis Execution Slide 9-24 Pjs Execution program Pis Signal Handler signal hndlr data stack & heap Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9

Toy Signal Handler Slide 9-25 #include static void sig_handler(int); int main () { int i, parent_pid, child_pid, status; if(signal(SIGUSR1, sig_handler) == SIG_ERR) printf(Parent: Unable to create handler for SIGUSR1\n); if(signal(SIGUSR2, sig_handler) == SIG_ERR) printf(Parent: Unable to create handler for SIGUSR2\n); parent_pid = getpid(); if((child_pid = fork()) == 0) { kill(parent_pid, SIGUSR1); for (;;) pause(); } else { kill(child_pid, SIGUSR2); printf(Parent: Terminating child \n); kill(child_pid), SIGTERM); wait(&status); printf(done\n); }

} Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Toy Signal Handler (2) static void sig_handler(int signo) { switch(signo) { case SIGUSR1: /* Incoming SIGUSR1 */ printf(Parent: Received SIGUSER1\n); break; case SIGUSR2: /* Incoming SIGUSR2 */ printf(Child: Received SIGUSER2\n); break; default: break; } return } Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-26

NT Event Object Slide 9-27 int main() { evntHandle[PART2] = CreateEvent(NULL, TRUE, FALSE, NULL); evntHandle[PART3] = CreateEvent(NULL, TRUE, FALSE, NULL); CreateThread(, threadY, ) ; // Create thread Y // Do part 1A SetEvent(evntHandle[PART2]); WaitForSingleObject(evntHandle[PART3]) ResetEvent(evntHandle[PART3]); // Do part 3A } Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 NT Event Object (cont)

DWORD WINAPI threadY(LPVOID) { // Do part 1B WaitForSingleObject(evntHandle[PART2]); ResetEvent(evntHandle[PART2]); // Do part 2 SetEvent(evntHandle[Part3]); // Do Part 3B } Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-28 Slide 9-29 NT Events Thread Thread Thread

Thread WaitForSingleObject(mutexR, time); Thread Thread WaitForSingleObject(mutexR, time); WaitForSingleObject(mutexR, time); Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 NT Mutex Object Slide 9-30 int main() { // This is a controlling thread // Open resource R // Create Mutex objects (signaled)

mutexR = CreateMutex(NULL, FALSE, NULL); CreateThread(, workerThrd, ) ; CreateThread(, workerThrd, ) ; } Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 NT Mutex Object (cont) Slide 9-31 DWORD WINAPI workerThrd(LPVOID) { while() { // Perform work // Obtain mutex while(WaitForSingleObject(mutexR) != WAIT_OBJECT_0); // Access the resource R ReleaseMutex(mutexR;) }

} Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-32 NT Events Thread Thread WaitForMultipleObjects(, objHnd, ); Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Waiting for Multiple Objects #define N HANDLE objHnd[N]; for(i = 0; i < N; i++) {

objHnd[I] = CreateThread(); } WaitForMultipleObjects(N, objHnd, TRUE, INFINITE); Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-33 NT Events Slide 9-34 Thread Thread CreateThread() WaitForSingleObject(foo, time); Set flag not signaled (Analogous to a P-operation)

Signaled/not signaled flag Kernel Kernelobject object Thread Object Copyright 2004 Pearson Education, Inc. Thread terminates become signaled (Analogous to a V-operation) Operating Systems: A Modern Perspective, Chapter 9 NT Waitable Timers Slide 9-35 Thread Thread SetWaitableTimer(delta) (Schedules an event occurrence) WaitForSingleObject(foo, time);

Set flag not signaled (Analogous to a P-operation) Signaled/not signaled flag Kernel Kernelobject object Waitable timer Copyright 2004 Pearson Education, Inc. Timer expires become signaled (Analogous to a V-operation) Operating Systems: A Modern Perspective, Chapter 9 Monitors Slide 9-36 Specialized form of ADT Encapsulates implementation

Public interface (types & functions) Only one process can be executing in the anADT { ADT at a time monitor semaphore mutex = 1; // Implicit . . . public: proc_i() { P(mutex); // Implicit ; V(mutex); // Implicit }; . . . }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Example: Shared Balance monitor sharedBalance { double balance; public: credit(double amount) {balance += amount;};

debit(double amount) {balance -= amount;}; . . . }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-37 Example: Readers & Writers Slide 9-38 monitor readerWriter_1 { int numberOfReaders = 0; int numberOfWriters = 0; boolean busy = FALSE; public: startRead() { reader(){ writer(){ }; while(TRUE) {

while(TRUE) { finishRead() { . . . . . . }; startRead(); startWriter(); startWrite() { finishRead(); finishWriter(); }; . . . . . . finishWrite() { } } }; fork(reader, 0); }; . . . fork(reader, 0): fork(writer, 0); . . . fork(writer, 0);

Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Example: Readers & Writers Slide 9-39 monitor readerWriter_1 { int numberOfReaders = 0; int numberOfWriters = 0; boolean busy = FALSE; public: startWrite() { startRead() { numberOfWriters++; while(numberOfWriters != 0) ; while( numberOfReaders++; busy || }; (numberOfReaders > 0) finishRead() { ) ;

numberOfReaders-; busy = TRUE; }; }; finishWrite() { numberOfWriters--; busy = FALSE; }; }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-40 Example: Readers & Writers Deadlock can happen monitor readerWriter_1 { int numberOfReaders = 0; int numberOfWriters = 0; boolean busy = FALSE; public: startWrite() { startRead() {

numberOfWriters++; while(numberOfWriters != 0) ; while( numberOfReaders++; busy || }; (numberOfReaders > 0) finishRead() { ) ; numberOfReaders--; busy = TRUE; }; }; finishWrite() { numberOfWriters--; busy = FALSE; }; }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Sometimes Need to Suspend Process obtains monitor, but detects a

condition for which it needs to wait Want special mechanism to suspend until condition is met, then resume Process that makes condition true must exit monitor Suspended process then resumes Condition Variable Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-41 Condition Variables Slide 9-42 Essentially an event (as defined previously) Occurs only inside a monitor Operations to manipulate condition variable wait: Suspend invoking process until another executes a signal

signal: Resume one process if any are suspended, otherwise do nothing queue: Return TRUE if there is at least one process suspended on the condition variable Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Active vs Passive signal Slide 9-43 Hoare semantics: same as active semaphore p0 executes signal while p1 is waiting p0 yields the monitor to p1 The signal is only TRUE the instant it happens Brinch Hansen (Mesa) semantics: same as passive semaphore p0 executes signal while p1 is waiting p0 continues to execute, then when p0 exits the monitor p1 can receive the signal Used in the Xerox Mesa implementation Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Hoare vs Mesa Semantics Slide 9-44 Hoare semantics: . . . if(resourceNotAvailable()) resourceCondition.wait(); /* now available continue */ . . . Mesa semantics: . . . while(resourceNotAvailable()) resourceCondition.wait(); /* now available continue */ . . . Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 2nd Try at Readers & Writers

Slide 9-45 monitor readerWriter_2 { int numberOfReaders = 0; boolean busy = FALSE; condition okToRead, okToWrite; public: startWrite() { startRead() { if(busy || (okToWrite.queue()) if((numberOfReaders != 0) || busy) okToRead.wait(); okToWrite.wait(); numberOfReaders++; busy = TRUE; okToRead.signal(); }; }; finishWrite() { finishRead() { busy = FALSE; numberOfReaders--; if(okToRead.queue())

if(numberOfReaders == 0) okToRead.signal() okToWrite.signal(); else }; okToWrite.signal() }; }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Example: Synchronizing Traffic One-way tunnel Can only use tunnel if no oncoming traffic OK to use tunnel if traffic is already flowing the right way Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Slide 9-46 Example: Synchronizing Traffic Slide 9-47 monitor tunnel { int northbound = 0, southbound = 0; trafficSignal nbSignal = RED, sbSignal = GREEN; condition busy; public: nbArrival() { if(southbound > 0) busy.wait(); northbound++; nbSignal = GREEN; sbSignal = RED; }; sbArrival() { if(northbound > 0) busy.wait(); southbound++; nbSignal = RED; sbSignal = GREEN; };

depart(Direction exit) ( if(exit = NORTH { northbound--; if(northbound == 0) while(busy.queue()) busy.signal(); else if(exit == SOUTH) { southbound--; if(southbound == 0) while(busy.queue()) busy.signal(); } } } Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Copyright 2004 Pearson Dining Philosophers again ... #define N ___ enum status(EATING, HUNGRY, THINKING}; monitor diningPhilosophers { status state[N]; condition self[N]; test(int i) { if((state[(i-1) mod N] != EATING) && (state[i] == HUNGRY) && (state[(i+1) mod N] != EATING)) { state[i] = EATING;

self[i].signal(); } }; public: diningPhilosophers() { // Initilization for(int i = 0; i < N; i++) state[i] = THINKING; }; Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-48 Dining Philosophers again ... test(int i) { if((state[(i-1) mod N] != EATING) && (state[i] == HUNGRY) && (state[(i+1) mod N] != EATING)) { state[i] = EATING; self[i].signal(); }; }; public: diningPhilosophers() {...};

pickUpForks(int i) { state[i] = HUNGRY; test(i); if(state[i] != EATING) self[i].wait(); }; putDownForks(int i) { state[i] = THINKING; test((i-1) mod N); test((i+1) mod N); }; } Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Copyright 2004 Pearson Slide 9-49 Experience with Monitors Danger of deadlock with nested calls Monitors were implemented in Mesa Used Brinch Hansen semantics Nested monitor calls are, in fact, a problem Difficult to get the right behavior with these semantics Needed timeouts, aborts, etc.

See paper by Lampson & Redell Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Slide 9-50 Slide 9-51 IPC Mechanisms Info copy Message Info to be shared Address Space for p0 OS IPC Mechanism

Address Space for p1 Must bypass memory protection mechanism for local copies Must be able to use a network for remote copies Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Refined IPC Mechanism Slide 9-52 Spontaneous changes to p1s address space Avoid through the use of mailboxes Address Space for p0 Address Space for p1 Mailbox for p1 Info Infoto tobe

be shared shared Message Message Message Message Message Message send( p1, ); Info Infocopy copy receive(); OS Interface send function Copyright 2004 Pearson Education, Inc.

receive Operating Systems: A Modern Perspective, Chapter 9 function Slide 9-53 Refined IPC Mechanism OS manages the mailbox space More secure message system Address Space for p0 Address Space for p1 Info Infoto tobe be shared shared Info

Infocopy copy send( p1, ); receive(); OS Interface Mailbox for p1 send function Copyright 2004 Pearson Education, Inc. Message Message Message Message Message Message Operating Systems: A Modern Perspective, Chapter 9

receive function Interprocess Communication (IPC) Slide 9-54 Signals, semaphores, etc. do not pass information from one process to another Monitors support information sharing, but only through shared memory in the monitor There may be no shared memory OS does not support it Processes are on different machines on a network Can use messages to pass info while synchronizing Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Message Protocols

Slide 9-55 Sender transmits a set of bits to receiver How does the sender know when the receiver is ready (or when the receiver obtained the info)? How does the receiver know how to interpret the info? Need a protocol for communication Standard envelope for containing the info Standard header A message system specifies the protocols Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Transmit Operations Slide 9-56 Asynchronous send: Delivers message to receivers mailbox Continues execution

No feedback on when (or if) info was delivered Synchronous send: Goal is to block sender until message is received by a process Variant sometimes used in networks: Until the message is in the mailbox Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 Receive Operation Blocking receive: Return the first message in the mailbox If there is no message in mailbox, block the receiver until one arrives Nonblocking receive: Return the first message in the mailbox If there is no message in mailbox, return with an indication to that effect Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Slide 9-57 Synchronized IPC Code for p1 Slide 9-58 Code for p2 /* signal p2 */ syncSend(message1, p2); ; /* wait for signal from p2 */ blockReceive(msgBuff, &from); syncSend() blockReceive() Copyright 2004 Pearson Education, Inc.

/* wait for signal from p1 */ blockReceive(msgBuff, &from); ; /* signal p1 */ syncSend(message2, p1); blockReceive() syncSend() Operating Systems: A Modern Perspective, Chapter 9 Slide 9-59 Asynchronous IPC Code for p1 Code for p2 /* signal p2 */ asyncSend(message1, p2); ; /* wait for signal from p2 */ while(!nbReceive(&msg, &from));

/* test for signal from p1 */ if(nbReceive(&msg, &from)) { ; asyncSend(message2, p1); }else< ; } nonblockReceive() asyncSend() nonblockReceive() nonblockReceive() nonblockReceive() Copyright 2004 Pearson Education, Inc. asyncSend() Operating Systems: A Modern Perspective, Chapter 9 UNIX Pipes

Slide 9-60 Address Space for p1 Info Infoto tobe be shared shared Info Infocopy copy write(pipe[1], ); System Call Interface read(pipe[0]); pipe for p1 and p2 write

function Copyright 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 read function UNIX Pipes (cont) The pipe interface is intended to look like a file interface Analog of open is to create the pipe File read/write system calls are used to send/receive information on the pipe What is going on here? Kernel creates a buffer when pipe is created Processes can read/write into/out of their address spaces from/to the buffer Processes just need a handle to the buffer Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Slide 9-61 UNIX Pipes (cont) File handles are copied on fork so are pipe handles int pipeID[2]; . . . pipe(pipeID); . . . if(fork() == 0) { /* the child */ . . . read(pipeID[0], childBuf, len); ; . . . } else { /* the parent */ . . . write(pipeID[1], msgToChild, len); . . . } Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Slide 9-62 UNIX Pipes (cont) The normal write is an asynchronous op (that notifies of write errors) The normal read is a blocking read The read operation can be nonblocking #include . . . int pipeID[2]; . . . pipe(pipeID); ioctl(pipeID[0], FIONBIO, &on); . . . read(pipeID[0], buffer, len); if(errno != EWOULDBLOCK) { /* no data */ } else { /* have data */ Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 Slide 9-63 Source, Filter and Sink Processes Source Copyright 2004 Pearson Education, Inc. Filter Operating Systems: A Modern Perspective, Chapter 9 Sink Slide 9-64 Information Flow Through UNIX Pipes Slide 9-65 Address Space for p1

Info Infoto tobe be shared shared Info Infocopy copy write(pipe[1], ); System Call Interface read(pipe[0]); pipe for p1 and p2 write function Copyright 2004 Pearson Education, Inc.

Operating Systems: A Modern Perspective, Chapter 9 read function

Recently Viewed Presentations

  • Seed3D P&amp;Cs nurturing innovation

    Seed3D P&Cs nurturing innovation

    Seed3D. Schools register for seed3D by Me3D. community member buys a Me2. school earns 10% off A me2 for every one sold. by *For full terms and conditions visit www ...
  • Module 1 - ANSTSE

    Module 1 - ANSTSE

    Slide 3-Module 3. FINISHED FILES ARE THE RESULT OF YEARS OF SCIENTIFIC STUDY COMBINED WITH THE EXPERIENCE OF MANY YEARS. Activity #1: Count the F's. ... Role Play. Brainstorming. Case Study. Gaming (i.e. Jeopardy, Family Feud, Bingo) PW page 3-14....
  • Welcome to Computer Organization and Assembly!

    Welcome to Computer Organization and Assembly!

    When there is no possible route to a piece of code in your program, that is called
  • &#x27;Praise Song My Mother&#x27; - WordPress.com

    'Praise Song My Mother' - WordPress.com

    In this poem the poet compares her mother to each of these objects. Can you think why? WRITE DOWN your ideas as we discuss them. Water. Moon. Sunrise. Red Gill. Flame Tree. Crab's Leg and fried Plaintain. Praise Song for...
  • BALANCE - Henry County School District

    BALANCE - Henry County School District

    BALANCE A Principle of Art Balance is a Principle of Art concerned with equalizing Elements (of Art) in a work of art. * Japanese for Paper folding. * Radial, Symmetrical, Asymmetrical * Relief Sculpture - Relief is a sculptural technique....
  • London Summer 2015 - Temple University Sites

    London Summer 2015 - Temple University Sites

    Pictures from 2013 and 2015. Clockwise from upper right: some 2013 students in front of the Museum of London; 2015 students on the Brick Lane Immigration and Street Art walk; a group of 2015 students in the Lake District, on...
  • Chapter 33

    Chapter 33

    Spanish-Cuban-American War (1898-1899) U.S. declares war in Spain after battleship Maine sunk in Havana harbor, 1898 Takes possession of Cuba, Puerto Rico, Guam, Philippines U.S. intervenes in other Caribbean, Central American lands; occupies Dominican Republic, Nicaragua, Honduras, Haiti Filipinos revolt...
  • GOODS AND SERVICES TAX (GST) - nirc@icai

    GOODS AND SERVICES TAX (GST) - [email protected]

    CONCEPT OF GST . World over in more than 150 countries there is GST or VAT, which means tax on goods and services. Under the GST scheme, no distinction is made between goods and services for levying of tax.