Index

Operating System

Processes

3.1 Process Concept

3.1.1 The Process


Figure 3.1 - A process in memory

3.1.2 Process State


Figure 3.2 - Diagram of process state

3.1.3 Process Control Block

For each process there is a Process Control Block, PCB, which stores the following ( types of ) process-specific information, as illustrated in Figure 3.1. ( Specific details may vary from system to system. )


Figure 3.3 - Process control block ( PCB )


Figure 3.4 - Diagram showing CPU switch from process to process

3.1.4 Threads

3.2 Process Scheduling

3.2.1 Scheduling Queues


Figure 3.5 - The ready queue and various I/O device queues

3.2.2 Schedulers


Figure 3.6 - Queueing-diagram representation of process scheduling


Figure 3.7 - Addition of a medium-term scheduling to the queueing diagram

3.2.3 Context Switch

3.3 Operations on Processes

3.3.1 Process Creation


Figure 3.8 - A tree of processes on a typical Linux system


Figure 3.11

3.3.2 Process Termination

3.4 Interprocess Communication


Figure 3.12 - Communications models: (a) Message passing. (b) Shared memory.

3.4.1 Shared-Memory Systems

Producer-Consumer Example Using Shared Memory

3.4.2 Message-Passing Systems

3.4.2.1 Naming
3.4.2.2 Synchronization
3.4.2.3 Buffering

3.5 Examples of IPC Systems

3.5.1 An Example: POSIX Shared Memory

  1. The ninth edition shows an alternate approach to shared memory in POSIX systems. Under this approach, the first step in using shared memory is to create a shared-memory object using shm_open( ),in a fashion similar to other file opening commands. The name provided will be the name of the memory-mapped file.
    shm_fd = shm_open( name,O_CREAT | O_RDRW,0666 );
  2. The next step is to set the size of the file using ftruncate:
    ftruncate( shm_fd, 4096 );
  3. Finally the mmap system call maps the file to a memory address in the user program space.and makes it shared. In this example the process that created the shared memory will be writing to it:
    ptr = mmap( 0, SIZE,PROT_WRITE, MAP_SHARED, shm_fd, 0 );
  4. The "borrower" of the shared memory, ( not the one who created it ), calls shm_open( ) and mmap( ) with different arguments, skips the ftruncate( ) step and unlinks ( removes ) the file name when it is done with it. Note that the "borrower" must use the same file name as the "lender" who created it. ( This information could have been passed using messages. )
    shm_unlink( name );
  5. Note that writing to and reading from the shared memory is done with pointers and memory addresses ( sprintf ) in both the 9th and 8th edition versions, even though the 9th edition is illustrating memory mapping of a file.
  6. Figures 3.17 and 3.18 from the ninth edition illustrate a complete program implementing shared memory on a POSIX system: