Simple Windows Job management (you didn't get it)

Source: Internet
Author: User

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");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.