What makes a application executable in Linux?
Applications are collections of executable files, shared-object files (DLLs in Windows-speak) and data files. In Windows, the file name is the indication; if the filename ends with one of a number of character patterns (.COM, .EXE, .DLL, .SCR, etc.), the Windows kernel will load and execute the file.
Linux uses a different mechanism from Windows to indicate whether a file can be executed or not. In Linux, a set of flags associated with the file (but not tied to the filename) indicates whether or not the file can be executed. These flags, called "execution bits" govern whether the operating system will permit the file's owner to execute it ("user execute"), and/or permit any other user in the group that owns the file to execute it ("group execute"), or any other user on the system to execute it ("other execute"). If the file doesn't have one of these three flags, the operating system won't permit the file to execute (see the ls(1), chmod(2), and stat(2) manual pages for details).
Linux adds a bit more flexibility than just these flags, though. In order for the operating system to execute the file, the file has to have a recognized execution mechanism registered with the operating system. For this, Linux uses a combination of "magic numbers" embedded in the file, and execution functions registered with the kernel.
As it reads the file in order to load it, the kernel recognizes the "magic number" in compiled programs (the "ELF header") and automatically invokes the system program loader (ld.so). Other "magic numbers" cause the OS to use other loaders to load and execute the file. For instance, the "magic number" #! will cause an "interpreter loader" to load the file and invoke the interpreter named after the magic number ("#!/bin/bash" as the first line of a script, for instance). Although the operating system defaults to a couple of loaders, new loaders can be registered with the system by updating the /proc/sys/fs/binfmt_misc file. (see the /usr/src/linux/Documentation/binfmt_misc.txt file for details).




