Live data from Hacker News

The world's smallest self-replicating program

ioccc.org

61–65 of 65 posts

Re: The world's smallest self-replicating program

#63
I once wrote an implementation of the classic Redcode "Imp" program in x86 assembly. It does not satisfy the requirements of this contest, but it does act as the Imp program, perpetually copying itself through RAM. :-)

I just uploaded it to https://github.com/mct/assembly-toys/tree/master/imp

Re: The world's smallest self-replicating program

#64
post #21

Earlier quoted context omitted.

No, without a shebang it is interpreted as a shell script.

Correct. A file will only be considered a binary executable if it has a proper header (ELF, Mach-O, etc) The default if no header and no shebang is to treat it like a shell script. In fact, an empty executable file has been used to implement /bin/true on some old systems. Why take the added cost of a disk seek when just the information in the inode will do?

I think this may only work if the executable is run by the shell, at least on Linux. If I recall correctly using exec() to execute it directly won't work, and there's special fallback code in the shell itself to run executables with neither a header nor shebang as shell scripts. It's generally safest to include the shebang.

Re: The world's smallest self-replicating program

#65

Earlier quoted context omitted.

Correct. A file will only be considered a binary executable if it has a proper header (ELF, Mach-O, etc) The default if no header and no shebang is to treat it like a shell script. In fact, an empty executable file has been used to implement /bin/true on some old systems. Why take the added cost of a disk seek when just the information in the inode will do?

>In fact, an empty executable file has been used to implement /bin/true on some old systems. Why take the added cost of a disk seek when just the information in the inode will do? why is this only on old systems? it seems very efficient.

Filesystems come and go. Not everyone has an executable bit.
Post reply on HN