2个不稳定版本
0.2.0 | 2023年1月9日 |
---|---|
0.1.0 | 2020年2月7日 |
#384 in Unix APIs
7,499 monthly downloads
16KB
208 lines
limits-rs
一个用于确定操作系统对特定进程施加的限制的Rust库。
操作系统支持
在其当前实现中,此crate允许方便地读取GNU/Linux上的/proc/<pid>/limits
文件。在其他任何平台上,提供的方法将返回错误,以便用户可以在缺少限制信息的情况下决定如何操作。
可根据需求添加对其他操作系统和平台的支持。请随意提交问题或创建PR!
示例
检查特定PID的限制
use limits_rs::get_pid_limits;
// Let's check what the CPU time hard limit is for process `1`.
let limits = get_pid_limits(1).unwrap();
let max_cpu_time_hard_limit = limits.max_cpu_time.hard;
// This will print either:
// - "Some(x)" if there is a limit, where `x` is the limit itself.
// - "None" if it is "unlimited".
println!("{}", max_cpu_time_hard_limit);
检查我们自己的PID的限制
use limits_rs::get_pid_limits;
// Let's check what the open files soft limit is for our own process.
let limits = get_own_limits().unwrap();
let max_open_files_soft_limit = limits.max_open_files.soft;
// This will print either:
// - "Some(x)" if there is a limit, where `x` is the limit itself.
// - "None" if it is "unlimited".
println!("{}", max_open_files_soft_limit);
支持的“可限制”属性
GNU/Linux
由limits-rs::linux::Limits
跟踪的属性有
max_cpu_time
max_file_size
max_data_size
max_stack_size
max_core_file_size
max_resident_set
max_processes
max_open_files
max_locked_memory
max_address_space
max_file_locks
max_pending_signals
max_msgqueue_size
max_nice_priority
max_realtime_priority
max_realtime_timeout
其他操作系统
如前所述,可根据需求添加对其他操作系统和平台的支持。请随意提交问题或创建PR!
许可证
Scriptful在MIT许可证和Apache许可证(版本2.0)的条款下分发。
有关详细信息,请参阅LICENSE-APACHE、LICENSE-MIT和COPYRIGHT。
依赖项
~265–720KB
~17K SLoC