• ulimit


    man ulimit:看到的是库函数里的帮助<ulimit.h>

    info ulimit 跟man ulimit一样,看到的是那个函数long ulimit(int cmd,long newLimit)

    这个函数已经obsolete(废弃),或者叫deprecated(不鼓励使用).因为它有替代者:getrlimit(2), setrlimit(2), sysconf(3)

    实际上,还有一个ulimit,它是shell的内置命令

    type ulimit: ulimit is a shell builtin
    help ulimit: 查看ulimit的帮助信息

    在shell中有6种方式提供帮助,应该根据type的种类来决定用man还是用help

      两次tab键

      help xxx :只能查看内置命令,help列出的全是精华,看它一晌会对bash有更好的巩固理解

      info xxx :在控制台下直接看帮助文档,外部命令和内部命令都适用

      man xxx :像看书一样看帮助,只适用于外部命令,man和info内容一样,只是表现方式略有差异.输入man,按两次tab键可以看到以man开头的命令.输入manpath可以看到man的目录,位于全局目录下的man命令就是在manpath所列路径中查找文件的.

      echo $PATH :然后可以cd到全局变量下面,去看有哪些可执行的命令

      一些小玩意:which,whereis,type查看命令的位置,类型等

    =====================help ulimit===================

    ulimit: ulimit [-SHabcdefilmnpqrstuvxT] [limit]
        Modify shell resource limits.对shell的子进程资源加以限制
        
        Provides control over the resources available to the shell and processes
        it creates, on systems that allow such control.
        
        Options:

      硬限制其实就是最大值,软限制就是当前值,不知道是谁给起个玄乎的名字.
          -S    use the `soft' resource limit 软限制,不得超过硬限制,设置之后还可以更改
          -H    use the `hard' resource limit 硬限制,设置时只能减少资源,设置之后只能改小,不能改大.如果不带参数,则默认参数为-H.软限制肯定小于等于硬限制,所以更改硬限制时,软限制可能会相应改变.
          -a    all current limits are reported 查看现在的全部限制
          -b    the socket buffer size 套接字缓冲区大小
          -c    the maximum size of core files created 内核文件大小
          -d    the maximum size of a process's data segment 进程数据段大小
          -e    the maximum scheduling priority (`nice') 最低的优先级
          -f    the maximum size of files written by the shell and its children 文件输出大小
          -i    the maximum number of pending signals
          -l    the maximum size a process may lock into memory
          -m    the maximum resident set size 常驻集大小
          -n    the maximum number of open file descriptors
          -p    the pipe buffer size 管道缓冲区大小
          -q    the maximum number of bytes in POSIX message queues
          -r    the maximum real-time scheduling priority
          -s    the maximum stack size 栈的最大值
          -t    the maximum amount of cpu time in seconds 运行时间
          -u    the maximum number of user processes 本进程及其子进程最大进程数
          -v    the size of virtual memory 虚存最大值
          -x    the maximum number of file locks 最大文件锁,也就是最多对多少文件加锁
          -T    the maximum number of threads 最大线程数
        
        Not all options are available on all platforms. 不同的平台对ulimit有不同的支持,ulimit并非所有的选项都能扩平台.
        
        If LIMIT is given, it is the new value of the specified resource; the
        special LIMIT values `soft', `hard', and `unlimited' stand for the
        current soft limit, the current hard limit, and no limit, respectively.
        Otherwise, the current value of the specified resource is printed.  If
        no option is given, then -f is assumed.

      如果在命令中给出了限制,那就是set;否则,那就是get.如果没有选项,那就默认-f选项,显示本进程树正在写的文件.
        
        Values are in 1024-byte increments, except for -t, which is in seconds,
        -p, which is in increments of 512 bytes, and -u, which is an unscaled
        number of processes.

      上面那些参数设值以1024byte递增(除了-t和-p选项,-t的单位是秒,-p的递增单位是512字节)
        
        Exit Status:
        Returns success unless an invalid option is supplied or an error occurs.

      如果运行成功,返回0.否则返回错误状态

    ====================ulimit -a=================================

    ulimit -a 查看全部限制

    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 15176
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 15176
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ====================ulimit -v ==============

    如果资源设置的少了,shell的很多外部命令都用不了,因为启动不了啊.输入help看到的全是内置命令,这些内置命令以就可以使用,因为他们是内置的,不会开启子进程去执行.资源设置少了,错误可能发生在程序运行的不同时期,于是就导致了不同的现象,下面这个例子,在虚拟内存逐渐变大的过程中出现了好几种错误.如果ulimit -Sv 1,就连按tab键出提示都用不了了.

    $ ulimit -Sv 1
    $ ls
    bash: /bin/ls: Argument list too long
    $ ulimit -Sv 10
    $ ls
    Segmentation fault
    $ ulimit -Sv 30
    $ ls
    Segmentation fault
    $ ulimit -Sv 300
    $ ls
    Segmentation fault
    $ ulimit -Sv 3000
    weidiao@ideapad:~/Desktop$ ls
    ls: error while loading shared libraries: libacl.so.1: failed to map segment from shared object
    $ ulimit -Sv 30000

  • 相关阅读:
    Linux下解析域名命令-dig 命令使用详解
    重写、覆盖、重载、多态几个概念的区别分析
    介绍python中运算符优先级
    介绍Python中6个序列的内置类型
    Mysql(Mariadb)数据库主从复制
    winscp中使用sudo的方法
    git push跳过用户名和密码认证配置教程
    案例:通过shell脚本实现mysql数据备份与清理
    毕业季,我的Linux求职之路
    PHP和ajax详解
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/5018738.html
Copyright © 2020-2023  润新知