简体   繁体   English

如何获取当前流程的作业对象(如果有)?

[英]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)?在 Windows Job Objects的上下文中,如何获取当前进程的作业对象(如果它在作业对象中)? The IsProcessInJob function lets me test whether a given process (eg the current one) is in a given (or any) job - but it doesn't yield the handle of the matching job.IsProcessInJob函数让我测试给定进程(例如当前进程)是否在给定(或任何)作业中 - 但它不会产生匹配作业的句柄。

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.如果您只想找出您正在运行的配额/限制,或枚举作业中的所有其他进程,则不需要获取当前进程的 Job 对象。

You can call QueryInformationJobObject with NULL, which will be the Job object of the current process.您可以使用 NULL 调用QueryInformationJobObject ,这将是当前进程的 Job 对象。

To answer the specific question, call IsProcessInJob find out if you are in a job.要回答特定问题,请致电IsProcessInJob了解您是否在工作。

You can find out everything about the Job by passing NULL to QueryInformationJobObject您可以通过将 NULL 传递给QueryInformationJobObject来查找有关 Job 的所有信息

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.您的子进程将自动继承您的工作,除非您通过CREATE_BREAKAWAY_FROM_JOB并且该工作具有JOB_OBJECT_LIMIT_BREAKAWAY_OKJOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK已设置。 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.因此,在不知道句柄的情况下,您可以找到有关当前作业的所有信息,并在当前作业中分配子进程,或者如果您有权限,则无需当前作业。 Ie 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.如果您需要这样做,您将不得不让父进程以某种方式将句柄值传达给您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM