Tuesday, July 12, 2016

git log exit code 141?

Something's that been bugging me for a while now is that when I do a `git log` command and quit before scrolling through all the output, my terminal prompt shows my last command (the git log) exited non-zero with status code 141.

I have git configured to use `less -+S` as the pager.

The answer turns out to be really straightforward, but took me a little bit of internet searching. I am capturing the learning here to save my future self the research and possibly anyone else typing the exact same thing into Google that I did ;-)

The explanation:

  • Git pipes the logs into less
  • I quit the less process, which sends a SIGPIPE signal (13) to the underlying git process streaming the logs
  • git catches the interrupt and exits prematurely and per POSIX convention returns 128 + the SIGPIPE status ==> 141 to indicate that it was terminated by signal 13
The background:
  1. http://stackoverflow.com/questions/19120263/why-exit-code-141-with-grep-q
  2. http://www.pixelbeat.org/programming/sigpipe_handling.html
  3. http://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated/99134#99134


  1. This comment has been removed by a blog administrator.

  2. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    SAS Training in Chennai | SAS Course in Chennai

  3. Is there any way to fix the exit code so that it is 0?

    1. Yes, change your git pager configuration to just `less`