【问题标题】:How can I get rid of "-bash: ulimit: open files" when I open terminal on my mac当我在我的 Mac 上打开终端时,如何摆脱“-bash: ulimit: open files”
【发布时间】:2015-03-11 03:27:27
【问题描述】:

每次我打开一个新终端时,都会显示这些消息:

-bash: ulimit: open files: cannot modify limit: Invalid argument
-bash: ulimit: max user processes: cannot modify limit: Operation not permitted

我之前确实修改过 ulimit,但是我忘记了我做了什么。那么我该如何解决这个问题,请帮助。谢了

----更新----

我的主目录中没有 .profile 或 .bashrc。但我有一个 ~/.bash_profile 和 /etc/bashrc。 ~/.bash_profile 看起来像

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GF'
alias ll='ls -GFl'

export JAVA_HOME=$(/usr/libexec/java_home)
export LC_CTYPE="en_US.UTF-8"

/etc/bashrc 看起来像:

# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
   return
fi

PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
        # Identify the directory using a "file:" scheme URL,
        # including the host name to disambiguate local vs.
        # remote connections. Percent-escape spaces.
    local SEARCH=' '
    local REPLACE='%20'
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
    printf '\e]7;%s\a' "$PWD_URL"
    }
    PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi

我没有看到任何关于 ulimit 的内容。

----更新----

sudo ulimit -a -H
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) unlimited
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 65532
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1064
virtual memory          (kbytes, -v) unlimited

sudo ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 4864
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited

【问题讨论】:

  • 查看您的配置文件:~/.profile~/.bash_profile~/.bashrc 并找到您尝试调用 ulimit 的位置。您可能需要查看/etc,但可能不会,除非您在那里修改配置文件等。
  • set -x 添加到~/.bash_profile 的顶部,将set +x 添加到底部。创建一个新的终端窗口。您应该看到~/.bash_profile 执行的命令的跟踪。找出生成错误消息的位置。如果它出现在跟踪代码之前或之后(您可能想在set +x 之后回显类似echo "Trace off" 的内容),那么您知道~/.bash_profile 没有产生问题;这是另一个文件。您可能必须阅读Bash 手册才能了解它读取的其他文件。一次调试一个文件。
  • @JonathanLeffler 既不是 /etc/bashrc 也不是 ~/.bash_profile :(
  • ulimit -a -Hulimit -a 的值是多少?将输出添加到您问题中的信息中。
  • @JonathanLeffler 已更新

标签: macos bash ulimit


【解决方案1】:

最后我解决了这个问题。我发现 OS X 在打开新终端时会加载 3 个配置文件,它们是“/etc/bashrc”、“/etc/profile”、“~/.bash_profile”。我在“/etc/profile”的底部找到了 2 行关于 ulimit 配置的信息。我删除了这两行并解决了这个问题。

无论如何,感谢@Jonathan Leffler,您提醒我查找导致此问题的其他配置文件。谢XD

【讨论】:

    猜你喜欢
    • 2021-07-25
    • 1970-01-01
    • 2010-11-08
    • 2023-01-29
    • 2019-11-19
    • 2022-12-14
    • 2019-08-28
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多