The ulimit command in Linux is an extremely useful command for system admins who manage multi-user systems.

对于管理多用户系统的系统管理员,Linux中的ulimit命令是非常有用的命令。

They need to have control over the resources being used by the users. This task can be made easy by setting limits for each user.

他们需要控制用户正在使用的资源。 通过为每个用户设置限制可以简化此任务。

The ulimit command in Linux is an essential tool for this purpose. This shell command enables us to check and set resource limits for all users on a Linux system. Setting the right limits goes a long way in ensuring that your system works optimally.

为此,Linux中的ulimit命令是必不可少的工具。 这个shell命令使我们能够检查和设置Linux系统上所有用户的资源限制。 设置正确的限制对确保系统以最佳状态运行大有帮助。

开始之前 (Before we start)

You need to have root user access or sudo non-root user access to be able to allocate resources for all the users.

您需要具有root用户访问权限或sudo非root用户访问权限,才能为所有用户分配资源。

ulimit命令的基本用法和选项 (Basic Usage and Options for the ulimit Command)

The ulimit command is a tool which is embedded in the shell. To launch ulimit, we simply type ‘ulimit‘ in the command line.

ulimit命令是嵌入在外壳中的工具。 要启动ulimit,我们只需在命令行中键入' ulimit '。


ulimit
Ulimit A
极限A

As you can see in the screenshot, we added the -a tag to display the limits for all the users.

如您在屏幕快照中所见,我们添加了-a标记以显示所有用户的限制。

The ulimit command in Linux allows various options to check and modify the limits for different system resources. These tags are shown in the table below.

Linux中的ulimit命令允许使用各种选项来检查和修改不同系统资源的限制。 这些标签如下表所示。

Tag Usage
-c Specifies the size of core dumps, in number of 512-byte blocks
-d Specifies the size of the data area, in number of K bytes.
-e the maximum scheduling priority (`nice’)
-s the maximum stack size
-u the maximum number of user processes. 
-T the maximum number of threads 
-b the maximum number of threads
标签 用法
-C 指定核心转储的大小,以512字节块为单位
-d 指定数据区域的大小,以K字节数为单位。
-e 最大调度优先级(“ nice”)
-s 最大堆栈大小
-u 用户进程的最大数量。
-T 最大线程数
-b 最大线程数

These are some of the most used options for the ulimit command in Linux. However, it can be difficult to remember all these tags on the top of your head.

这些是Linux中ulimit命令最常用的一些选项。 但是,可能很难记住所有这些标签在您的头上。

So, if you wish to use an option but you can’t remember the functionality, use the –help tag to get a list of all the options available for the command.

因此,如果您希望使用某个选项但不记得其功能,请使用–help标记获取该命令可用的所有选项的列表。

熟悉limits.conf (Getting familiar with limits.conf)

All the resource limits for a user is saved in a file named limits.conf, holding the configuration for all user limits. This file is saved in the directory at /etc/security/limits.d by default, which can hold resource limit configurations for multiple users.

用户的所有资源限制都保存在名为limits.conf的文件中,其中包含所有用户限制的配置。 此文件默认情况下保存在目录/etc/security/limits.d中 ,该目录可以容纳多个用户的资源限制配置。

Let’s take a look at the limits.conf file using the cat command

让我们使用cat命令查看limits.conf文件

Ulimit Conf
Ulimit Conf
极限极限

Here, the configuration file deals with four parameters:

在这里,配置文件处理四个参数:

  1. domain
  2. type
    类型
  3. item
    项目
  4. value

Let’s look at each of these parameters individually.

让我们分别查看每个参数。

1.域参数 (1. The domain Parameter)

We start with the ‘domain’. This defines the domain to which a limit belongs. It can be a specific user, a group of users or even a wildcard. The two wildcards available here are as follows.

我们从“域”开始。 这定义了限制所属的域。 它可以是特定用户,一组用户甚至是通配符。 此处可用的两个通配符如下。

  • * – This refers to the default entry for the domain
    * –这是指域的默认条目
  • % – This is used used to specify maxlogin limit
    %–用于指定最大登录限制

These help the root user to define the user or the group of users to set a limit for.

这些帮助root用户定义用户或要为其设置限制的用户组。

2.类型参数 (2. The type Parameter)

Next comes ‘type’. This refers to the type of limit which we wish to set for our user. There are two types of limits for us to choose from.

接下来是“类型”。 这是指我们希望为用户设置的限制类型。 有两种类型的限制供我们选择。

  • soft- These are limits which can be exceeded by a user if required using the ulimit function
    soft-这些限制是用户可以使用ulimit函数超出的限制
  • hard- These limits are fixed by the root user and cannot be changed by anyone without root access to the system
    硬-这些限制由root用户固定,没有root访问系统权限的任何人都不能更改

Note that any kind of limits can only be set by a user with root access. Any other user can only edit the soft limits set for them if needed.

请注意,任何种类的限制只能由具有root访问权限的用户设置。 如果需要,任何其他用户只能编辑为其设置的软限制。

3.项目参数 (3. The item Parameter)

The third parameter refers to the ‘item’ or the resource which we wish to limit. The resource can be selected by writing their reference name. Here is a list of resources and their reference names.

第三个参数指的是“项目”或我们希望限制的资源。 可以通过写参考名称来选择资源。 这是资源及其参考名称的列表。

Ulimit Conf Item Parameter
Ulimit Conf项目参数

4.值参数 (4. The value Parameter)

The last parameter refers to the ‘value’ or the actual limit for our item. The unit for each value is associated with its corresponding item.

最后一个参数指的是我们商品的“值”或实际限制。 每个值的单位与其对应的项目相关联。

Let’s move on to learning how to set user limits.

让我们继续学习如何设置用户限制。

在ulimit文件中设置值 (Setting the Values in the ulimit File)

Now that you understand what the parameters are, let’s set some limits.

现在您了解了参数是什么,让我们设置一些限制。

Suppose you want to set a max data size limit to the “journaldev” as 4096kb, you can add a line at the end of the file in the following format:

假设要将“ journaldev”的最大数据大小限制设置为4096kb,则可以在文件末尾以以下格式添加一行:


journaldev hard data 4096

设置/更改飞行限制 (Setting/Changing Limits on the Fly)

You can also set limits on the fly using the ulimit command. This will temporarily

您还可以使用ulimit命令即时设置限制。 这将暂时

NOTE: Resource limits on a system are set to make sure your system doesn’t run out of memory. These settings are essential to maintain the balance of resources on your system. Editing the ulimit values without proper knowledge can cause your system to misbehave or even stop working.

注意:设置系统上的资源限制以确保您的系统不会耗尽内存。 这些设置对于维持系统资源的平衡至关重要。 在没有适当知识的情况下编辑ulimit值可能会导致系统行为异常,甚至停止工作。

When you wish to change a limit, you simply need to call the ulimit command in Linux, followed by the limit option and the limit which you wish to set. An example of this is shown below.

当您希望更改限制时,只需在Linux中调用ulimit命令,然后调用limit选项和您要设置的限制。 下面是一个示例。


ulimit -c unlimited

This command will set the limit for your core file size (denoted by the -c tag) to ‘unlimited’. Using this command, you can easily set limits for any system resource as per your requirement.

此命令会将您的核心文件大小(由-c标记表示)的限制设置为“无限制”。 使用此命令,您可以根据需要轻松设置任何系统资源的限制。

You can verify the change using the ulimit command with the appropriate tag as shown earlier in this tutorial.

您可以使用带有相应标记的ulimit命令来验证更改,如本教程前面所示。

Remember, changing the limits can only be done if the limits are set as soft limits in the limits.conf file. For hard limits, only the root user has access to modification of the limits.

请记住,只有在limits.conf文件中将限制设置为软限制时,才可以更改限制。 对于硬限制,只有root用户有权访问限制的修改。

结论 (Conclusion)

This tutorial aimed to introduce you to the ulimit command and its functionalities. There are many more things one can do using the ulimit command in Linux.

本教程旨在向您介绍ulimit命令及其功能。 在Linux中使用ulimit命令可以做很多事情。

So make sure you explore by typing man ulimit and info ulimit in your terminal to get in-depth information about the ulimit command.

因此,请确保在终端中输入man ulimitinfo ulimit进行探索,以获得有关ulimit命令的深入信息。

翻译自: https://www.journaldev.com/38026/ulimit-command-in-linux

如何在Linux中使用ulimit命令相关推荐

  1. linux系统export,Linux入门进阶 - 如何在Linux中使用export命令

    原标题:Linux入门进阶 - 如何在Linux中使用export命令 来自: Linux迷 链接:https://www.linuxmi.com/linux-export.html Linux ex ...

  2. linux如何export文件夹,学习如何在Linux中使用export命令

    Linux export命令会标记哪些值需要传递给一组子进程.这是bash shell提供的一个简单但有用的特性.它允许管理员在不中断当前会话的情况下传递环境的配置参数.这就是为什么在终端会话重新启动 ...

  3. Linux入门进阶 - 如何在Linux中使用export命令

    Linux export命令会标记哪些值需要传递给一组子进程.这是bash shell提供的一个简单但有用的特性.它允许管理员在不中断当前会话的情况下传递环境的配置参数.这就是为什么在终端会话重新启动 ...

  4. linux xargs命令_如何在Linux中使用xargs命令?

    linux xargs命令 The xargs command allows us to pass the output of one command as the input for another ...

  5. linux chown命令 例子,如何在Linux中使用chown命令[基本示例]

    Linux中的chown命令允许您更改文件和目录的所有权. 下面是一张快速记忆的图片: 使用chown命令,可以更改文件或目录的用户和组所有权. Linux中的chown命令示例 以下是chown命令 ...

  6. 如何在Linux中使用history命令

    随着我在终端会话中花费越来越多的时间,感觉就像我一直在寻找使我的日常任务更加高效的新命令一样. GNU history命令确实改变了我的工作日. GNU history命令保留了从该终端会话运行的所有 ...

  7. linux可以修改日期格式吗,如何在Linux中使用date命令修改日期时间

    Linux中可使用date命令查看修改日期及时间,本例中以CentOS6为例说明. 1.直接输入"date"可查看当前系统日期及时间(普通用户即可执行此命令). 2.输入" ...

  8. 如何在Linux中使用netstat命令

    The term "netstat" stands for Network Statistics. In layman's terms, netstat command displ ...

  9. linux中mkfs是什么命令,如何在Linux中使用mkfs命令[用于磁盘格式化]

    mkfs中的字母代表"制作文件系统".命令通常用于管理Linux中的存储设备,你可以将mkfs看作是将磁盘格式化为特定文件系统的命令行工具.mkfs -t [fs type] [t ...

最新文章

  1. springmvc接收前台(可以是ajax)传来的数组list,map,set等集合,复杂对象集合等图文详解...
  2. 网络优化正在从经验型优化向大数据关联分析优化转变
  3. 数据库 ACCESS与SQL SERVER 2000分页SQL语句 分析
  4. socket编程总结
  5. nginx向响应内容中追加内容(ngx_http_addition_module模块)
  6. 计算机基础及wps office应用_自考本科计算机应用基础考试大纲
  7. java script创建对象_JavaScript七种非常经典的创建对象方式
  8. 三 jQuery 选择器
  9. git 删除分之以及删除文件夹
  10. OpenCV实现验证otsu算法
  11. java 多线程任务队列_精简的java 线程池与任务队列
  12. VB.NET控件应用编程实例教程(奋斗的小鸟)_PDF 电子书
  13. eclipse安装教程|最详细eclipse安装 配置图文教程
  14. JavaScript实现动态显示时间
  15. 解决“npm WARN requires a peer of XXX“问题
  16. Sitemesh小记
  17. Fast R-CNN文章详细解读
  18. 【报告分享】2021国民健康洞察报告-丁香(附下载)
  19. html页面打印+区域,实现web网页指定区域打印的三种方法
  20. python-yaml文件使用(PyYAML)

热门文章

  1. 学习python 基础密码验证
  2. 用户控件页为什么找不到.ClientScript.RegisterClientScriptBlock原因
  3. 在无法单步调试的情况下找Bug的技巧
  4. ubuntu下安装beanstalkd
  5. [转载] python zip 文件解压中文乱码问题解决
  6. [转载] Python列表拷贝复制函数copy()函数的作用
  7. [转载] Python:numpy中array的用处
  8. 2019暑假绍兴第一中学游记
  9. SpringBoot史前简述
  10. (25)软件工程开发规范