1

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?

Camelid
  • 1,535
  • 8
  • 21

1 Answers1

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.

Nuno
  • 76
  • 3