How do I know if bash terminal hangs or if a process is just taking a while?

I was in the same place as this guy where I thought a process had caused bash to hang, but instead it was just taking a while. I ran gem install berkshelf, and fortunately, the process showed up on Activity Monitor, so I knew it was still going, but is there a more reliable way to do this?

1

2 Answers

You actually cannot tell the difference between a process hanging or "just taking a while". A process can respond to signals, but does not have to.

When a process "hangs", it probably got stuck in an infinite loop, or is waiting for some event that never happens. But it could also just do a lot of work.

For example, a process that does intensive work might not immediately react to Ctrl-C (a SIGINT termination signal), but could exit a little later, or not at all. That's usually the case where you send a SIGKILL, which cannot be ignored by a process.

Note that in this whole situation, the actual shell (e.g., Bash) is never hanging. Simply speaking, the shell just executes the process and puts it into the foreground. You could still suspend the process and continue running it in the background (Ctrl-Z, then bg). Your shell would still work.

2

A good thing to do is to run processes that take a long time in verbose mode. That way you can see progress and if it hangs, you know where and can (hopefully) resolve the problem. Also, (by default, with stty sane) Ctrl+C sends SIGINT, but Ctrl+Z sends SIGTSTP.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like