2

Running timeout 0.01s git status on a large repo where git status takes about a second doesn't do anything different from git status. I.e., timeout doesn't seem to interrupt Git when it takes too long. Why would this be?

1
  • If you're trying to use Git's status in your shell prompt, you may want an asynchronous prompt. I'm using tide for the Fish shell, and it's great. Presumably, there are other similar options for Bash and Zsh. Commented Oct 16 at 12:56

1 Answer 1

2

By default, the timeout command simply sends a SIGTERM signal whenever the timeout expires. This signal can be caught and ignored by processes, which would cause the process not to terminate. Git is probably ignoring the SIGTERM.

From the timeout's manpage:

If no signal is specified, send the TERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. It may be necessary to use the KILL (9) signal (...)

If you really need it to timeout, you can use the -k switch to send a SIGKILL instead. Use at your own risk. This may or may not corrupt you repo:

timeout -k 0.02s 0.01s git status

This will first send a SIGTERM after 0.01s and then a SIGKILL after 0.02s of the first signal.

Note that you need to pass two durations (one for SIGTERM and one for SIGKILL). I suggest you use a longer duration (e.g. 1s), otherwise git will probably not be able to do anything useful, depending on the size of your repo.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there no way to have Git obey the SIGTERM?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.