简体   繁体   English

bash中的制表符竞争挂起“选择”

[英]Tab competion in bash hangs at “select”

Recently my tab completion in bash has become annoyingly slow. 最近,我在bash中完成的制表符变得非常缓慢。 I enter part of a directory name and hit Tab , but it takes over a half second for the directory name to be completed. 我输入目录名称的一部分,然后按Tab ,但是完成目录名称需要花费半秒钟的时间。 To debug, I ran strace on the shell process from another terminal while I ran the tab completion, and found that a call to "select" was taking up the time: 为了进行调试,我在运行选项卡补全的同时从另一个终端在shell进程上运行了strace,发现对“ select”的调用占用了时间:

06:06:35.379778 select(1, [0], NULL, [0], {0, 500000}) = 0 (Timeout) 06:06:35.881344 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0

You can clearly see that the call to select times out after 500ms. 您可以清楚地看到select的调用在500ms之后超时。 I ran the same experiment in my local machine (this problem is happening on my company-provided VM) and observed that there is no call to select at all. 我在本地计算机上进行了相同的实验(此问题在我公司提供的VM上发生),并观察到根本没有select呼叫。 My VM is running bash version 4.3.11(1)-release (x86_64-pc-linux-gnu) and my local machine is running 4.3.48(1)-release (x86_64-pc-linux-gnu) 我的VM正在运行bash版本4.3.11(1)-release (x86_64-pc-linux-gnu)发行版4.3.11(1)-release (x86_64-pc-linux-gnu)而我的本地计算机正在运行4.3.48(1)-release (x86_64-pc-linux-gnu)

How can I debug this further? 如何进一步调试? Should I just upgrade bash? 我应该升级bash吗?


In response to Emily's comment: 针对艾米丽的评论:

~: complete
~: complete -r
~: echo $PROMPT_COMMAND

~: trap
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU

I had a similar problem. 我有一个类似的问题。 Plenty of disk space, plenty of CPU and memory, but tab completion would regularly hang for 0.5 to 1.5 seconds. 足够的磁盘空间,大量的CPU和内存,但是制表符补全通常会挂起0.5到1.5秒。 I ran strace and also saw the hang was at a pselect. 我跑了一下,还看到挂起处是一个pselect。

I fixed it by changing the _tilde() function in /usr/share/bash-completion/bash-completion to always immediately return 0. It seems a comparison ( if [[ $1 == \\~* && $1 != */* ]]; then ... ) is taking a long time to complete. 我通过将/usr/share/bash-completion/bash-completion_tilde()函数更改为始终立即返回0来修复它。这似乎是一个比较( if [[ $1 == \\~* && $1 != */* ]]; then ... )需要很长时间才能完成。

Adding a " return 0 " at the beginning of the function made things go faster, and didn't seem to have any adverse effects. 在函数的开头添加“ return 0 ”可以使事情进展得更快,并且似乎没有任何不利影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM