Hacker News new | past | comments | ask | show | jobs | submit login

By comparison, OpenBSD's version:

  /*      $OpenBSD: true.c,v 1.1 2015/11/11 19:05:28 deraadt Exp $        */

  /* Public domain - Theo de Raadt */

  int
  main(int argc, char *argv[])
  {
        return (0);
  }



Which is, actually, far too large due to the standard library, program state initialization, and stack frame management. If there's ever a practical use for code golf, this is probably it. /bin/true should be a bare minimum ELF executable with no stack or heap that does nothing except immediately make the system call to terminate.


As mentioned in the article:

" This can be done with an empty file that's marked executable, and that's what it was in the earliest unix system libraries. "

    $ uname -sr
    OpenBSD 6.1
    $ install -m 755 /dev/null /tmp/muhtrue && /tmp/muhtrue && echo yup 
    yup
not sure why it was ever switched.. probably the 'return 0;' version is cheaper than a shell fork? hmm..


She’ll forks are expensive. Very expensive.

Of course the system could have special cased a zero length executable file.


*shell forks



Well this code might do exactly what you just said.

Everything depends with which compiler flags you build this code. I know for sure there are MSVS flags to build this program with no runtime and other things with just return asm op in it.


Most likely nobody uses /bin/true (/usr/bin/true).

Executing true without the pathname will run the shell embedded function.


Needing a program that returns true comes up more often than just shell scripting. For example, maybe a system reports an event by launching a named executable. Specifying /bin/true is the equivalent of redirecting that event to /dev/null.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: