5.6 Job Object events and completion ports
(1) associating the Job object with the completion port object
Jobobject_associate_completion_port JOACP;
JOACP. Completionkey = hJob1; can be used to identify any unique value of a Job Object , where its handle is taken
JOACP. Completionport = HIOCP; handle to completion port
Setinformationjobobject (Hjob,jobobjectassociatecompletionportinformation,
&joacp,sizeof (JOACP));
(2) creates a thread that passes the completion port object as a parameter to the thread function. and GetQueuedCompletionStatus to wait for a notification event for the Job object.
|
Parameters |
Describe |
|
HIOCP |
Handle of the completion port object to get the event |
|
Pnumbytestransferred |
Event ID to wait for
"Events related to Job Object"
①job_object_msg_active_process_limit: The number of active processes in the Job object reaches the limit notification
②Job_object_msg_active_process_zero: Notification when there are currently no active processes in the Job Object
③job_object_msg_end_of_job_time: The Job Object exhausts the specified time period notification. However, the process does not automatically terminate. You can set a new time limit to allow continuation, or call Terminatejobobject to terminate the process.
④job_object_msg_job_memory_limit: The Job Object exhausts the specified memory notification while giving the process ID
"Process-related events"
①job_object_msg_new_process: Notifies when a new process joins the Job object and gives the process ID.
②job_object_msg_exit_process: Notifies when the process exits gracefully and gives the process ID.
③job_object_msg_abnormal_exit_process: Notification when the process exits unexpectedly and gives the process ID
④job_object_msg_end_of_process_time: Process runs out of time notifications, process terminates, and process ID is given
⑤job_object_msg_process_memory_limit: The process consumes memory up to the time limit notification, and the process IDis given.
|
|
pcompletionkey |
Specifies the handle of the job object that triggered the event ( ) |
|
poverlapped |
In a job event, The value represents which id . |
|
Dwmilliseconds |
Used to specify when the caller waits for the port to complete |
Note:
① the state of a Job object becomes self-triggering when the time to allocate a job expires, not when all processes end.
② by default, when the job time expires, all its processes are automatically terminated, so the job_object_msg_end_of_job_timeis not delivered. If you just want to send the notification to the application and let the application kill the process by itself, you can do the following:
// Create a struct and fill in the structure with the actions to take at the end of the JOb
jobobject_end_of_job_time_information joeojti;
Joeojti. Endofjobtimeaction = Job_object_post_at_end_of_job; // deliver notifications instead of "kill" the process. When the job is created, the default value is job_object_terminate_at_end_of_job;
// tell the Job object what to take when the job time expires
setinformationjobobject (hjob,jobobjectendofjobtimeinformation,
&joeojti,sizeof (JOEOJTI));
"Jobio" uses completion ports for process management
5th Job and Process Pool (2)