Chapter 2: homework
1. to process a group of processes as a separate group, Windows provides a job kernel object, it allows us to combine processes and create a "sandbox" to limit what processes can do. It is best to think of a job object as a process container. Understanding: here we should pay attention to the key. A job is the container that manages the process set. The so-called management is mainly to restrict process behavior!
2. If a process has been associated with a job, it cannot remove the current process or any of its sub-processes from the job. This security feature ensures that the process cannot get rid of the restrictions imposed on it.
3. check whether a process is associated with a job and use the isprocessinjob function.
4. Use the createjobobject function to create a job.
5. Use the setinformationjobobject function to impose restrictions on processes in the job. Please refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms686216 (V = vs.85) for the limit type ). aspx: the content that limits jobs is the focus of this chapter. There are dozens of types, and the corresponding structure and impact on processes vary.
6. use the assignprocesstojobobject function to put the process into the job. If you want to manage the process while creating the process, you should use the create_supended flag when creating the process, add it to the job list, and then start the process. Once a process is already part of a job, it cannot be moved to another job or become "unemployed". When one process in the job generates another process, the new process automatically becomes a part of the job of the parent process (however, you can use special parameters to get the child process out of control when creating the child process through CreateProcess ).
7. Use the terminatejobobject function to terminate all processes in the job. It is done by calling terminateprocess for each process. The memory cleanup after each process is terminated is left to the System for Automatic completion.
8. Use the queryinformationjobobject function to query the current limits of a job. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms684925 (V = vs.85). aspx for query type parameters. In addition to query restrictions, you can also query job statistics. Note that the type parameter here is not exactly the same as the setinformationjobobject type parameter. Every structure is worth further research. The convenience of writing this interface and the quality of the instructions in this document are not flattering.
9. Job notifications are implemented through the completion port. After the port is created, use the setinformationjobobject parameter with jobobjectassociatecompletionportinformation to bind the port handle to the job. In this way, the system will monitor jobs. As long as there are events, they will be shipped to the I/O completion port. We call getqueuedcompletionstatus to monitor the completion port (generally, the monitoring action is performed by another thread, use queryinformationjobobject to obtain the completion key and the completion port handle ).
10. It is important for users to handle the port events completed by jobs.
11. for my understanding of the CD code of jeffreyrichter, In the 05-joblab program, I found that the CMD window created by the process that created the job has been associated with the job successfully, however, you cannot find the process information through queryinformationjobobject. You have sent a message to Microsoft. I hope you can get an answer.
The content of the accompanying book code is available in many places. But I also uploaded the one I used: http://download.csdn.net/detail/eagleatustb/4690967