开发者

Why does a bash alias sometimes delay returning results?

开发者 https://www.devze.com 2023-03-14 16:42 出处:网络
Occasionall开发者_C百科y I will open a shell and use: alias ll=\"ls -l\" (set in my .bashrc file) and it will take nearly 8 seconds to return the very simple \'ls -l\' command results. 8 seconds is

Occasionall开发者_C百科y I will open a shell and use:

alias ll="ls -l"

(set in my .bashrc file) and it will take nearly 8 seconds to return the very simple 'ls -l' command results. 8 seconds isn't 'long' - but you could type ls -l and beat the return of the alias command in that time.

Does anyone know what would cause/fix this? Some sort of caching would be my guess...


C'mon: how do you know it is the alias expansion? It isn't!

It is most likely the disk spinning up, memory pages being swapped in, slow drive serving /usr/bin/ls ... etc.

It could be an expression in $PS1 or $PROMPT_COMMAND. Many things.

If you really want to know, try running

$ strace -c ls -l

to find out where it it spending time and post the results if you need help interpreting that. Of course, wait for an instance where it ran slowly if that doesn't happen all the time (if my hypothesis is right, leave the PC for a while or force your disk to spin-down with (as root):

for a in /dev/sd?; do hdparm -Y $a; done
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号