3

There is a certain user who when they press tab key to complete a file path, it takes several seconds for the machine to make the completion. They are using the bash shell.

How can I diagnose what exactly is causing the tab completion to hang for this user?

LINUX G33NYUS
  • 716
  • 1
  • 12
  • 22
  • 2
    `set -x` would be a good start – Jeff Schaller Apr 04 '17 at 19:01
  • 2
    If you talking about path completion, look for a unreachable directory on the $PATH – Stephen Rauch Apr 04 '17 at 19:37
  • in addition to unreachable path, search those folders in $PATH and make sure there is not 10,000+ files/folders within them. Typically this should not be the case but if the user modified his/her $PATH variable you never know. And backtrack to setting PATH to its original OEM contents such as `/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin` and verify tab completion works. Then one step at a time modify PATH to what it was when the problem was happening to maybe find the problem folder. – ron Apr 04 '17 at 20:07
  • I typically start with a dpkg --purge bash-completion as my first command in any root shell. – peterh Jan 01 '19 at 05:47

1 Answers1

4

In bash, run echo $$ to see the shell's process ID, then get ready to press Tab in bash. Open another terminal and run strace -p1234 where 1234 is the process ID of bash. strace will print a trace of the system calls that bash executes. Even if you don't understand exactly what is going on, this is often enough to understand what is taking time — typically it's making a network request, or it's accessing a very large number of files. Figuring out what settings to change to avoid the slowness may or may not be easy.

Depending on your system's security settings, you may not be allowed to run strace on an unrelated process. If you aren't, then run strace as the parent of bash:

strace -tt -T -o bash.trace bash

Do the completion attempt then exit bash and look at the trace file bash.trace. Each line has a timestamp at the beginning indicating when the system call started, and the number in angle brackets at the end of the line is the time spent in the system call.

strace is a Linux command. If you aren't running Linux, look up the corresponding command on your system — dtrace, truss, trace, …

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • These 5 things stood out as taking the most time. What do you make of it? 15:23:28.764131 read(0, "\t", 1) = 1 <0.920741> 15:23:36.005376 read(0, "i", 1) = 1 <1.103554> 15:23:34.330527 read(0, "e", 1) = 1 <1.449958> 15:23:32.041462 read(0, "\r", 1) = 1 <2.282322> 15:23:25.030097 read(0, "c", 1) = 1 <2.638741> – LINUX G33NYUS Apr 10 '17 at 20:08
  • 1
    @LINUXG33NYUS `read(0, …)` means reading from file descriptor 0, which is standard input, which is the terminal. This is you typing... – Gilles 'SO- stop being evil' Apr 10 '17 at 20:11
  • What about these? 17:45:08.590201 read(3, "", 128) = 0 <0.007714> 17:45:08.285093 read(3, "y\n", 128) = 2 <0.007059> 17:45:09.869542 read(3, "", 128) = 0 <0.003091> 17:45:10.190572 read(3, "", 128) = 0 <0.002741> – LINUX G33NYUS Apr 10 '17 at 22:00
  • @LINUXG33NYUS These are fast, they aren't a problem unless there are too many of them, and anyway you'd need to know what file descriptor 3 is. If you want help with this, post the whole trace (but if this gets too complicated I might ask you to ask a new question). – Gilles 'SO- stop being evil' Apr 10 '17 at 22:08
  • I tried to post it here but it says too long by 75380 characters. Is there somewhere else I can post it? – LINUX G33NYUS Apr 11 '17 at 17:03