开发者

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

开发者 https://www.devze.com 2023-02-18 19:06 出处:网络
In the context of Windows Job Objects, how can I get the开发者_StackOverflow job object for the current process (in case it is in a job object)? The IsProcessInJob function lets me test whether a give

In the context of Windows Job Objects, how can I get the开发者_StackOverflow 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消