zoukankan      html  css  js  c++  java
  • 解决-bash: fork: retry: Resource temporarily unavailable (修改最大线程数)

    错误提示的本质是Linux操作系统无法创建更多进程,导致出错。
    因此要解决这个问题需要修改Linux允许创建更多的进程。

    方案一:
    cat /etc/security/limits.conf

    echo "* soft nproc 2047" >>/etc/security/limits.conf
    echo "* hard nproc 16384" >>/etc/security/limits.conf

    sed -i 's/^*/#*/g' /etc/security/limits.d/90-nproc.conf

    方案二:
    通过ulimit -a来查看当前Linux系统的一些系统参数

    $ 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) 62357
    max locked memory (kbytes, -l) 64
    max memory size (kbytes, -m) unlimited
    open files (-n) 65536
    pipe size (512 bytes, -p) 8
    POSIX message queues (bytes, -q) 819200
    real-time priority (-r) 0
    stack size (kbytes, -s) 10240
    cpu time (seconds, -t) unlimited
    max user processes (-u) 1024
    virtual memory (kbytes, -v) unlimited
    file locks (-x) unlimited

    在上面这些参数中,通常我们关注得比较多的是一个进程可打开的最大文件数,即open files。
    系统允许创建的最大进程数量即是max user processes 这个参数。
    我们可以使用 ulimit -u 4096 修改max user processes的值,但是只能在当前终端的这个session里面生效,重新登录后仍然是使用系统默认值。
    正确的修改方式是修改/etc/security/limits.d/90-nproc.conf文件中的值。


    $ cat /etc/security/limits.d/90-nproc.conf
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.

    * soft nproc 4096

    我们只要修改上面文件中的4096这个值,即可。


    方案三:(临时生效)

    ulimit -u 2048

  • 相关阅读:
    LeetCode 242. Valid Anagram (验证变位词)
    LeetCode 205. Isomorphic Strings (同构字符串)
    LeetCode 204. Count Primes (质数的个数)
    LeetCode 202. Happy Number (快乐数字)
    LeetCode 170. Two Sum III
    LeetCode 136. Single Number (落单的数)
    LeetCode 697. Degree of an Array (数组的度)
    LeetCode 695. Max Area of Island (岛的最大区域)
    Spark中的键值对操作
    各种排序算法总结
  • 原文地址:https://www.cnblogs.com/sprinng/p/6902169.html
Copyright © 2011-2022 走看看