3.2 Anatomy of a Process

The address space of a process is divided into three logical segments: text (program code), data and stack segments. Figure 3-1 shows the logical layout of a process. The text segment is at the bottom of the address space. The text segment contains the instructions to be executed, called the program code . The data segment above it contains the initialized global, external, and static variables for the process. The stack segment contains locally allocated variables and parameters passed to functions. Because a process can make system function calls as well as user -defined function calls, two stacks are maintained in the stack segment, the user-stack and the kernel-stack. When a function call is made, a stack-frame is constructed and pushed onto either the user or kernel stack depending on whether the process is in user or kernel mode. The stack segment grows downward toward the data segment. The stack frame is popped from the stack when the function returns. The text, data, stack segments, and process control block are part of what forms the process image.

Figure 3-1. The address space of a process divided into the text, data, and stack segments. This is the logical layout of a process.

graphics/03fig01.gif

The address space of a process is virtual . Virtual storage dissociates the addresses referenced in an executing process from the addresses actually available in internal memory. This allows the addressing of storage space much larger than what is available. The segments of the process's virtual address space are contiguous blocks of memory. Each segment and physical address space are broken up into chunks called pages . Each page has a unique page frame number . The virtual page frame number is used as an index into the process's page tables. The page table entries contain a physical page frame number, thus mapping the virtual page frames to physical page frames . This is depicted in Figure 3-2. As illustrated , virtual address space is contiguous but it is mapped to physical pages in any order.

Figure 3-2. The contiguous virtual page frames mapped to pages in physical memory.

graphics/03fig02.gif

Although the virtual address space of each process is protected to prevent another process from accessing it, the text segment of a process can be shared among several processes. Figure 3-2 also shows how two processes can share the same program code. The same physical page frame number is stored in the page table entries of both processes' page tables. As illustrated in Figure 3-2, process A virtual page frame 0 is mapped to physical page frame 5 as well as process B's virtual page frame 2.

In order for the operating system to manage all the processes stored in internal memory, it creates and maintains process tables . Actually, the operating system has a table for all of the entities that it manages. Keep in mind that the operating system manages not only processes but all the resources of the computer including devices, memory, and files. Some of the memory, devices, and files are managed on behalf of the user processes. This information is referenced in the PCB as resources allocated to the process. The process table will have an entry for each process image in memory. Each entry contains the process and parent process id, real and effective user id and group id, list of pending signals, the location of the text, data, and stack segments, and the current state of the process. When the operating system needs to access a process, the process is looked up in the process table and then the process image is located in memory. This is depicted in Figure 3-3.

Figure 3-3. The operating system control tables. Each entry in the process table stores represents a process in the system.

graphics/03fig03.gif



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net