Home > Articles > Operating Systems, Server > Microsoft Servers

  • Print
  • + Share This
This chapter is from the book

Job Objects

Processes can be collected together into job objects where the processes can be controlled as a group, resource limits can be specified for all the job object member processes, and accounting information can be maintained. Job objects were introduced with Windows 2000 and are supported in all NT5 systems.

The first step is to create an empty job object with CreateJobObject, which takes two arguments, a name and security attributes, and returns a job object handle. There is also an OpenJobObject function to use with a named object. CloseHandle destroys the job object.

AssignProcessToJobObject simply adds a process specified by a process handle to a job object; there are just two parameters. A process cannot be a member of more than one job, so AssignProcessToJobObject fails if the process associated with the handle is already a member of some job. A process that is added to a job inherits all the limits associated with the job and adds its accounting information to the job, such as the processor time used.

By default, a new child process created with CreateProcess will also belong to the job unless the CREATE_BREAKAWAY_FROM_JOB flag is specified in the dwCreationFlags argument to CreateProcess. In the default case, AssignProcessToJobObject will fail if you attempt to assign the child process to a job.

Finally, you can specify control limits on the processes in a job using SetInformationJobObject.

BOOL SetInformationJobObject (
   HANDLE hJob,
   JOBOBJECTINFOCLASS JobObjectInformationClass,
   LPVOID lpJobObjectInformation,
   DWORD cbJobObjectInformationLength)
  • hJob is a handle for an existing job object.

  • JobObjectInformationClass specifies the information class for the limits you wish to set. There are five values; JobObjectBasicLimitInformation is one value and is used to specify information such as the total and per-process time limits, working set size limits, [2] limits on the number of active processes, priority, and processor affinity (the processors of an SMP system that can be used by threads in the job processes).

  • lpJobObjectInformation points to the actual information required by the preceding parameter. There is a different structure for each class.

  • JOBOBJECT_BASIC_ACCOUNTING_INFORMATION allows you to get the total time (user, kernel, and elapsed) of the processes in a job.

  • The last parameter is the length of the preceding structure.

QueryJobInformationObject obtains the current limits. Other information classes impose limits on the user interface, I/O completion ports (see Chapter 14), security, and job termination.

  • + Share This
  • 🔖 Save To Your Account