Bash randomly hangs for a few seconds after executing a command. At that stage, Ctrl+C
or anything just gets printed on the terminal.
I use tmux, so I had already opened up htop to view resource usage in a different pane. All was fine. Also, when it is hung, moving to other panes works fine, I can type anything, but it hangs up when I press Enter. All of the panes execute as soon as the first pane which was hung continues. The point being resources are not a bottleneck.
I tried to use set -x
in bash to check if something is happening, but due to unpredictable hangs, I had to revert it back to keep working sanely.
I also looked up How to profile a bash shell script slow startup?, but I can't find a way in there, to find slow bash after executing a command.
Any ideas how do I debug it? I am slowly going mad.
Edit: To add more context, the hang varies from 5 seconds to a minute.
To give an example, consider this:
$ ls
<--- hangs here
// after a few seconds, it continues
file1.txt
<--- never hangs here, after executing the cmd
$
And this is just an example, nothing to do with ls
. I find no correlation to any particular command by which I can reproduce this.