How to get the task object (if any) for my current process?

In the context of Windows Task Objects , how can I get a task object for the current process (in case it is in the task object)? The IsProcessInJob function allows me to check whether a given process (for example, the current one) is in a given (or any) task, but it don’t enter a matching job descriptor.

+6
c ++ c windows process winapi
source share
1 answer

If you just want to find out what quotas / limits are you using or list all the other processes in the task, you do not 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.

To answer a specific question, call IsProcessInJob to see if you work.

You can learn all about the job by passing NULL to QueryInformationJobObject

Your child processes automatically inherit your job if you do not pass CREATE_BREAKAWAY_FROM_JOB and job JOB_OBJECT_LIMIT_BREAKAWAY_OK or JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK . In these cases, you can assign the process to a new task if you wish.

Thus, without knowing the descriptor, you can find out everything about your current task and assign child processes in the current task, or if you have permission, without the current work. That is, you can do almost anything that a pen allows you to do.

The only exception is to duplicate it to another marriage process. If you need to do this, you will have to somehow tell the parent process the value of the handle.

+11
source share

All Articles