Processes

References:

  1. Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts, Eighth Edition ", Chapter 3

3.1 Process Concept

3.1.1 The Process

3.1.2 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. )

3.1.4 Threads

3.2 Process Scheduling

3.2.1 Scheduling Queues

3.2.2 Schedulers

3.2.3 Context Switch

3.3 Operations on Processes

3.3.1 Process Creation

3.3.2 Process Termination

3.4 Interprocess Communication

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 first step in using shared memory is for one of the processes involved to allocate some shared memory, using shmget:

    int segment_id = shmget( IPC_PRIVATE, size, S_IRUSR | S_IWUSR );

    • The first parameter specifies the key ( identifier ) of the segment. IPC_PRIVATE creates a new shared memory segment.
    • The second parameter indicates how big the shared memory segment is to be, in bytes.
    • The third parameter is a set of bitwise ORed flags. In this case the segment is being created for reading and writing.
    • The return value of shmget is an integer identifier
  2. Any process which wishes to use the shared memory must attach the shared memory to their address space, using shmat:

    char * shared_memory = ( char * ) shmat( segment_id, NULL, 0 );

    • The first parameter specifies the key ( identifier ) of the segment that the process wishes to attach to its address space
    • The second parameter indicates where the process wishes to have the segment attached. NULL indicates that the system should decide.
    • The third parameter is a flag for read-only operation. Zero indicates read-write; One indicates readonly.
    • The return value of shmat is a void *, which the process can use ( type cast ) as appropriate. In this example it is being used as a character pointer.
  3. Then processes may access the memory using the pointer returned by shmat, for example using sprintf:
  4. sprintf( shared_memory, "Writing to shared memory\n" );

  5. When a process no longer needs a piece of shared memory, it can be detached using shmdt:
  6. shmdt( shared_memory );

  7. And finally the process that originally allocated the shared memory can remove it from the system suing shmctl.

    shmctl( segment_id, IPC_RMID );

  8. Figure 3.16 illustrates a complete program implementing shared memory on a POSIX system .

3.5.2 An Example: Mach

3.5.3 An Example: Windows XP

3.6 Communication in Client-Server Systems

3.6.1 Sockets

3.6.2 Remote Procedure Calls, RPC

3.6.3 Pipes

3.6.3.1 Ordinary Pipes

3.6.3.2 Named Pipes

OLD 3.6.3 Remote Method Invocation, RMI ( Removed from 8th edition )


Figure omitted in 8th edition


Figure omitted in 8th edition

3.7 Summary