You might not believe that these are real programs but they are. You can find the binaries using `whereis`. For example on my linux install true is /bin/true.
The command line is pretty awesome.
http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob_p...
/bin/true source is a bit longer than expected but /bin/false implementation is really interesting : http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob_p...
Yeah, but try telling your boss that :)
$ touch foo
$ chmod +x foo
$ ./foo
$ echo $?
0 $ touch empty
$ chmod +x empty
$ time ./empty
real 0m0.002s
user 0m0.000s
sys 0m0.000s
$ echo "int main(){return 0;}" > trivial.c
$ gcc trivial.c -o trivial
$ time ./trivial
real 0m0.001s
user 0m0.000s
sys 0m0.000s
Timing results are consistent over several repetitions (provided everything's in cache from disk). Linux x86_64. `mov` takes ten thousand to a million times less than a millisecond ( https://gist.github.com/jboner/2841832 ), so I can't find out this way whether removing 'return 0' changes anything.(If I use my default zsh shell to execute ./empty, it gives me
zsh: exec format error: ./empty
./empty 0.00s user 0.00s system 0% cpu 0.008 total
So I used bash for this.)This is the normal pattern, just in case you forget to put "#!/bin/bash" at the top of the script, so that the script can be run anyway. This is also a source of confusion for some sysadmins, when a script works from the command line but not from something like a cron script.
Comparing to all this, a move instruction in userland won't really make a difference.
Edit: List on system calls required to execute trivial.c (on my Linux):
execve, brk, access, mmap, access, open, open, open, open, open, stat, open, stat, open, stat, open, stat, open, fstat, mmap, close, access, open, read, fstat, mmap, mprotect, mmap, mmap, close, mmap, mmap, mmap, arch_prctl, mprotect, mprotect, munmap, exit_group
$ touch empty
$ chmod +x empty
$ time ./empty
real 0m0.005s
user 0m0.001s
sys 0m0.001s
$ echo "int main(){return 0;}" > trivial.c
$ gcc trivial.c -o trivial
$ time ./trivial
real 0m0.002s
user 0m0.001s
sys 0m0.002s