Chapter 4 -- Processes

[Previous] [Next]

Chapter 4

This chapter discusses how the system manages all of the running applications. I'll begin by explaining what a process is and how the system creates a process kernel object to manage each process. I'll then show you how to manipulate a process using its associated kernel object. Following that, I'll discuss the various attributes, or properties, of a process as well as several functions for querying and changing these properties. I'll also examine the functions that allow you to create or spawn additional processes in the system. And, of course, no discussion of processes would be complete without an in-depth look at how they terminate. OK, let's begin.

A process is usually defined as an instance of a running program and consists of two components:

  • A kernel object that the operating system uses to manage the process. The kernel object is also where the system keeps statistical information about the process.
  • An address space that contains all the executable or DLL module's code and data. It also contains dynamic memory allocations such as thread stacks and heap allocations.

Processes are inert. For a process to accomplish anything, it must have a thread that runs in its context; this thread is responsible for executing the code contained in the process's address space. In fact, a single process might contain several threads, all of them executing code "simultaneously" in the process's address space. To do this, each thread has its own set of CPU registers and its own stack. Each process has at least one thread that executes code in the process's address space. If there were no threads executing code in the process's address space, there would be no reason for the process to continue to exist, and the system would automatically destroy the process and its address space.

For all of these threads to run, the operating system schedules some CPU time for each thread. It creates the illusion that all the threads run concurrently by offering time slices (called quantums) to the threads in a round-robin fashion. Figure 4-1 shows how this works on a machine with a single CPU. If the machine has multiple CPUs, the operating system's algorithm is much more complex to load balance the threads over the CPUs.

click to view at full size.

Figure 4-1. The operating system offers quantums to individual threads in a round-robin fashion on a single-CPU machine.

When a process is created, the system automatically creates its first thread, called the primary thread. This thread can then create additional threads, and these can in turn create even more threads.

Windows 2000
Microsoft Windows 2000 can use machines with multiple CPUs. For example, the machine I am using to write this manuscript contains two processors. Windows 2000 can have different threads executing on each CPU so that multiple threads do truly run simultaneously. The Windows 2000 kernel handles all the management and scheduling of threads on this type of system. You do not have to do anything special in your code to gain the advantages offered by a multiprocessor machine.

Windows 98
Windows 98 can take advantage of only a single processor. Even if the machine contains more than one processor, Windows 98 can schedule only a single thread at a time; any other processors sit dormant.



Programming Applications for Microsoft Windows
Programming Applications for Microsoft Windows (Microsoft Programming Series)
ISBN: 1572319968
EAN: 2147483647
Year: 1999
Pages: 193

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