C H A P T E R
6
Process Management
A process contains its own independent virtual address space with both code and data, protected from other processes. Each process, in turn, contains one or more independently executing threads. A thread running within a process can create new threads, create new independent processes, and manage communication and synchronization between the objects. By creating and managing processes, applications can have multiple, concurrent tasks processing files, performing computations, or communicating with other networked systems. It is even possible to exploit multiple processors to speed processing. This chapter explains the basics of process management and also introduces the basic synchronization operations that will be used throughout the rest of the book. Windows Processes and Threads
Every process contains one or more threads, and the Windows thread is the basic executable unit. Threads are scheduled on the basis of the usual factors: availability of resources such as CPUs and physical memory, priority, fairness, and so on. Windows has supported symmetric multiprocessing (SMP) since NT4, so threads can be allocated to separate processors within a system. From the programmer’s perspective, each Windows process includes resources such as the following components: • One or more threads. • A virtual address space that is distinct from other processes’ address spaces, except where memory is explicitly shared. Note that shared memory-mapped files share physical memory, but the sharing processes will use different virtual addresses to access the mapped file. • One or more code segments, including code in DLLs. 163
MP 64:2 4002 ,82 rebmetpeS , yadseuT 461 e gaP mf.60hc_traH
164
CHAPTER 6
PROCESS MANAGEM ENT
• One or more data segments containing global variables. • Environment strings with environment variable information, such as the current search