First put the code out, and later have time to study! Simply put, the job is equivalent to a sandbox, allowing the program to be active within a certain range.
#include "stdafx.h"
#include "Windows.h"
#include <iostream>
using namespace Std;
Security_attributes sa;
Startupinfo si={sizeof (SI)};
Process_information Pi;
void Main ()
{
HANDLE Hjob=createjobobject (&sa, "test");
Jobobject_basic_limit_information JB;
Jb. Priorityclass=idle_priority_class;
Jb. perprocessusertimelimit.quadpart=1000;
Jobobject_basic_ui_restrictions Jbur;
Jbur. Uirestrictionsclass = job_object_uilimit_none|
Job_object_uilimit_exitwindows | Job_object_uilimit_handles;
Setinformationjobobject (Hjob,
Jobobjectbasiclimitinformation,
&JB,
sizeof (Jobobject_basic_limit_information)
);
Setinformationjobobject (hjob,jobobjectbasicuirestrictions,&jbur,sizeof (Jbur));
CreateProcess (NULL, "Ping www.baidu.com-t", null,null,true,create_suspended| CREATE_NEW_CONSOLE,NULL,NULL,&SI,&PI);
Assignprocesstojobobject (hjob,pi.hprocess);
ResumeThread (Pi.hthread);
CloseHandle (Pi.hthread);
FILETIME CreationTime, Exittime, Kerneltime, Usertime;
Getprocesstimes (pi.hprocess, &creationtime, &exittime, &kerneltime, &usertime);
Getprocesstimes (GetCurrentProcess, &creationtime, &exittime, &kerneltime, &UserTime);
cout << TEXT ("Kernel =") << kerneltime.dwlowdatetime << "and User ="
<< usertime.dwlowdatetime << Endl;
CloseHandle (pi.hprocess);
CloseHandle (Hjob);
System ("pause");
}