[][src]Crate win32job

wun32job-rs

A safe API for Windows' job objects, which can be used to set various limits to processes associated with them. See also Microsoft Docs.

Using the higher level API

After getting an ExtendedLimitInfo object, either by querying the info of a job or by creating an empty one using new(), use helper methods to configure the required limits, and finally set the info to the job.

This code runs with edition 2018
use win32job::*;

let mut info = ExtendedLimitInfo::new();

info.limit_working_memory(1 * 1024 * 1024,  4 * 1024 * 1024)
    .limit_priority_class(PriorityClass::BelowNormal);

let job = Job::create_with_limit_info(&mut info)?;
job.assign_current_process()?;

Which is equivalnent to:

This code runs with edition 2018
use win32job::*;

let job = Job::create()?;
let mut info = job.query_extended_limit_info()?;

info.limit_working_memory(1 * 1024 * 1024,  4 * 1024 * 1024)
    .limit_priority_class(PriorityClass::BelowNormal);

job.set_extended_limit_info(&mut info)?;
job.assign_current_process()?;

Using the low level API

The most basic API is getting an ExtendedLimitInfo object and manipulating the raw JOBOBJECT_BASIC_LIMIT_INFORMATION, and then set it back to the job.

It's important to remeber to set the needed LimitFlags for each limit used.

This code runs with edition 2018
use win32job::*;
use winapi::um::winnt::JOB_OBJECT_LIMIT_WORKINGSET;

let job = Job::create()?;
let mut info = job.query_extended_limit_info()?;

info.0.BasicLimitInformation.MinimumWorkingSetSize = 1 * 1024 * 1024;
info.0.BasicLimitInformation.MaximumWorkingSetSize = 4 * 1024 * 1024;
info.0.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_WORKINGSET;

job.set_extended_limit_info(&mut info)?;
job.assign_current_process()?;

Modules

utils

Structs

ExtendedLimitInfo
Job

Enums

JobError
PriorityClass