Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the job object (if any) for my current process?

In the context of Windows Job Objects, how can I get the job object for the current process (in case it is in a job object)? The IsProcessInJob function lets me test whether a given process (e.g. the current one) is in a given (or any) job - but it doesn't yield the handle of the matching job.

like image 706
Frerich Raabe Avatar asked Mar 18 '11 14:03

Frerich Raabe


1 Answers

If you just want to find out what quotas/limits you are running under, or enumerate all the other processes in the job, you don't need to get the Job object for the current process.

You can call QueryInformationJobObject with NULL, which will be the Job object of the current process.

  • QueryInformationJobObject: http://msdn.microsoft.com/en-us/library/ms684925(VS.85).aspx
  • Job Objects: http://msdn.microsoft.com/en-us/library/ms684161(VS.85).aspx
  • Set job attributes using SetInformationJobObject

To answer the specific question, call IsProcessInJob find out if you are in a job.

You can find out everything about the Job by passing NULL to QueryInformationJobObject

Your child processes will inherit your job automatically, unless you pass CREATE_BREAKAWAY_FROM_JOB and the job has JOB_OBJECT_LIMIT_BREAKAWAY_OK or JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK is set. In these cases you can assign the process to a new job if you wish.

So without knowing the handle, you can find out all about your current Job, and assign child processes within the current job, or if you have permission, without the current job. I.e. you can do almost everything the handle would allow you to do.

The only exception is duplicate it to another sibling process. If you need to do that you will have to have the parent process communicate the handle value to you somehow.

like image 95
Ben Avatar answered Oct 04 '22 18:10

Ben