July 17th Monday (七月 十七日 火曜日)

本文介绍getrlimit和setrlimit系统调用,它们允许进程读取和设置系统资源消耗的限制。文章详细解释了硬限制和软限制的概念,并列举了一些常用的资源限制类型,如CPU使用时间、数据内存分配大小等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  The getrlimit and setrlimit system callsallow a process to read and set limits on the
system resources that it can consume.You may be familiar with the ulimit shell command,
which enables you to restrict the resource usage of programs you run; these system calls
allow a program to do this programmatically.

  For each resource there are two limits,the hard limit and the soft limit.The soft limit
may never exceed the hard limit,and only processes with superuser privilege may
change the hard limit.Typically,an application program will reduce the soft limit to
place a throttle on the resources it uses.

  Both getrlimit and setrlimit take as arguments a code specifying the resource
limit type and a pointer to a structrlimit variable.The getrlimit call fills the fields
of this structure,while the setrlimit call changes the limit based on its contents.The
rlimit structure has two fields:rlim_cur is the soft limit,and rlim_max is the hard
limit.

  Some of the most useful resource limits that may be changed are listed here,with
their codes:

* RLIMIT_CPU--The maximum CPU time,in seconds,used by a program.This is
the amount of time that the program is actually executing on the CPU,which is
not necessarily the same as wall-clock time.If the program exceeds this time
limit,it is terminated with a SIGXCPU signal.

* RLIMIT_DATA--The maximum amount of memory that a program can allocate
for its data.Additional allocation beyond this limit will fail.

* RLIMIT_NPROC--The maximum number of child processesthat can be running
fork and too many processes belonging to this for this user.If the process calls
user are running on the system,fork fails.

* RLIMIT_NOFILE--The maximum number of file descriptors that the process may
have open at one time.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值