【文章內(nèi)容簡介】
a fork to replace the process’ memory space with a new program. Process operation: Process termination ? Process executes last statement and asks the operating system to decide it (exit). ? Output data from child to parent (via wait). ? Process’ resources are deallocated. ? Parent may terminate execution of children processes (abort). ? Child has exceeded allocated resources. ? Task assigned to child is no longer required. ? Parent is exiting. ? Operating system does not allow child to continue if its parent terminates. ? Cascading termination. PROCESS COOPERATING ? Independent processes vs cooperating processes ? Independent process cannot affect or be affected by the execution of another process. ? Cooperating process can affect or be affected by the execution of another process ? Why process cooperation? ? Information sharing ? Computation speedup ? Modularity (system) ? Convenience (user) ? Mechanisms for process cooperation ? Communication and ? synchronization Process cooperating: The Producerconsumer problem ? The producerconsumer problem: a producer process produces information that is consumed by a consumer process. ? Print program ? print driver, ? Compiler ? assembler ? loader. ? Communication choices: ? IPC (Interprocessmunication), ? Shared memory. SHARED MEMORY COMMUNICATION ? A buffer pool: filled by the producer and consumed by the consumer. ? unboundedbuffer places no practical limit on the size of the buffer, ? boundedbuffer assumes that there is a fixed buffer size. Shared memory: BoundedBuffer – SharedMemory Solution ? Shared data define BUFFER_SIZE 10 typedef struct { . . . } item。 item buffer[BUFFER_SIZE]。 int in = 0。 int out = 0。 Shared memory: BoundedBuffer – SharedMemory Solution ? Producer process item nextProduced。 while (1) { while(((in + 1)%BUFFER_SIZE) == out) 。 /* do nothing */ buffer[in] = nextProduced。 in = (in + 1) % BUFFER_SIZE。 } Shared memory: BoundedBuffer – SharedMemory Solution ? Consumer Process item nextConsumed。 while (1) { while (in == out) 。 /* do nothing */ nextConsumed = buffer[out]。 out = (out + 1) % BUFFER_SIZE。 } INTERPROCESS COMMUNICATION (IPC) ? IPC . Sharedmemory ? Efficiency, ? Centralized vs Dis