限制 Linux 中用户可用的内存和 CPU
我有点关心共享计算机中可以使用的资源量。 有什么方法可以测试管理员是否对我可以使用的资源量有限制? 如果是的话,为了提出一个更完整的问题,我该如何设置这样的限制?
I am a little concerned with the amount of resources that I can use in a shared machine. Is there any way to test if the administrator has a limit in the amount of resources that I can use? And if does, to make a more complete question, how can I set up such limit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于与进程相关的限制,您可以查看
/etc/security/limits.conf
(阅读文件中的注释,使用 google 或使用man limits.conf
更多信息)。 正如 jpalecek 指出的那样,您可以使用 ulimit -a 来查看(并可能修改)当前有效的所有此类限制。您可以使用命令
quota
查看磁盘配额是否有效。For process related limits, you can have a look in
/etc/security/limits.conf
(read the comments in the file, use google or useman limits.conf
for more information). And as jpalecek points out, you may useulimit -a
to see (and possibly modify) all such limits currently in effect.You can use the command
quota
to see if a disk quota is in effect.您可以尝试运行
以查看哪些资源限制有效。 另外,如果允许您更改此类限制,则可以通过 ulimit 命令更改它们,例如。
解除进程可以创建的核心文件大小的任何限制。
You can try running
to see what resource limits are in effect. Also, if you are allowed to change such limits, you can change them by the
ulimit
command, eg.lifts any limit for a size of a core file a process can make.
在C层面,相关函数(实际上是syscalls(2)...) 可能是 setrlimit(2)和 setpriority(2) 和 sched_setattr(2)。 您可能希望从您的 shell 中调用它们。
另请参阅 proc(5) - 并尝试
cat /proc/self/limits
和 sched(7) 。您可能需要使用 renice(1) 命令。
如果您运行一个持久的程序(几个小时)不需要用户交互,您可以考虑使用一些批处理处理。 某些 Linux 系统有
batch
或at< /代码>命令
。
At the C level, the relevant functions (actually syscalls(2)...) could be setrlimit(2) and setpriority(2) and sched_setattr(2). You probably would want them to be called from your shell.
See also proc(5) -and try
cat /proc/self/limits
and sched(7).You may want to use the renice(1) command.
If you run a long-lasting program (for several hours) not requiring user interaction, you could consider using some batch processing. Some Linux systems have a
batch
orat
command.