An executable file is a file containing a program in a form that an operating system or runtime environment can load and run. In its narrowest sense, it contains machine code for a particular processor architecture, together with information needed to prepare that code for execution. In broader usage, the term also includes scripts and intermediate-code programs run by an interpreter or other runtime. Whether a file can execute depends on its contents, the available execution environment, and applicable permissions—not simply its filename.
Executable files and running programs
An executable file is a stored representation of a program, whereas a process is an active instance of a program being executed. The same executable can support multiple processes, each with its own execution state and usually its own address space.
Executables differ from ordinary data files mainly in how the system treats their contents. An image viewer interprets an image as data; a program loader interprets an executable’s structure as instructions for constructing a running program. This distinction is contextual: a developer’s inspection tool can read an executable as data without running it.
A native executable is also distinct from source code, the human-readable program from which it may have been produced. Source code generally requires translation or interpretation before its operations can be carried out. However, an executable script can itself be source code, so “source file” and “executable file” are not mutually exclusive categories.
Main types
Native executables
A native executable contains instructions compatible with the target processor’s instruction set architecture. Its file format also supplies information required by the operating system, such as memory-layout instructions, dependency information, and an entry point.
Native executables are usually platform-specific. A program built for one processor family cannot ordinarily run directly on another. Even programs targeting the same processor may require different executable formats, operating-system services, or calling conventions.
Scripts
A script contains instructions in a programming language that an interpreter executes. On many Unix-like systems, an executable script begins with a shebang line, such as #!/bin/sh, which identifies the interpreter to invoke.
A script does not have to be directly launchable to run. For example, an interpreter can open a readable script supplied as an argument even when the script lacks execute permission. Conversely, marking a text file executable does not ensure that its contents form a valid program.
Managed and intermediate-code programs
Some programs are distributed as bytecode or another intermediate representation rather than native processor instructions. A virtual machine or managed runtime interprets this representation or compiles it into machine code during execution.
Examples include Java class files and assemblies targeting the .NET runtime. Their launch mechanisms differ: some are opened through a runtime command, while others use a platform-specific executable launcher. They are executable in the broader sense, but not necessarily native executables that the operating-system kernel can load directly.
Internal structure and common formats
An executable is usually more than a sequence of processor instructions. Depending on its format and purpose, it may contain:
- Headers identifying the format, target architecture, and file characteristics.
- Program code containing instructions to execute.
- Initialized data, such as constants and initial variable values.
- Descriptions of zero-initialized memory, which need not occupy an equivalent amount of file space.
- An entry point, where execution begins after required setup.
- Dependency and relocation information, used to locate external code and adjust addresses.
- Resources and diagnostic information, such as icons, version records, symbols, or debugging data.
Sections used by build and inspection tools are not always identical to the regions mapped into memory. A loader may organize execution around segments or comparable mapping units rather than individual sections.
Three widely used format families are:
| Format | Typical environments | Notable characteristics |
|---|---|---|
| [[executable-and-linkable-format | Executable and Linkable Format]] (ELF) | [[linux |
| [[portable-executable | Portable Executable]] (PE) | [[microsoft-windows |
| [[mach-o | Mach-O]] | macOS and other Apple operating systems |
A format family can cover files that are not independently launchable. For example, an object file or shared library may use the same broad format as an executable while serving a different role.
Creation and linking
A common native build pipeline translates source code with a compiler, produces one or more object files, and combines them using a linker. An assembler may also participate, translating assembly instructions into machine code.
Object files typically contain code and data that are not yet ready to form a complete running program. The linker resolves references among components, lays out program content, and records information needed for later loading.
With static linking, selected library code is incorporated into the executable. With dynamic linking, the program relies on libraries located and loaded at startup or during execution. These approaches can be combined within one program.
Static linking can reduce dependence on separately installed libraries, but it does not automatically make a program independent of its operating system or external resources. Dynamic linking can allow multiple programs to use the same library installation, while introducing requirements concerning library availability and compatible versions.
Debugging symbols may be embedded in the executable, stored separately, or removed from a distribution build. Their removal reduces diagnostic information; it does not make the underlying machine instructions secret.
Loading and execution
When a native executable is launched, the system generally performs several related operations:
- Recognizes the file format and checks whether it is supported.
- Checks execution permissions and policy, including relevant security restrictions.
- Establishes a process image, mapping code and data into virtual memory.
- Prepares dependencies, invoking a dynamic linker or runtime where necessary.
- Initializes execution state, including the stack, arguments, and environment.
- Transfers control to an entry point.
The details vary across operating systems. On Unix-like systems, the exec family of interfaces replaces the calling process’s program image rather than inherently creating a new process. A command shell commonly creates a child process before requesting that replacement.
The entry point is not necessarily the source-language function conventionally called main. Runtime startup code may initialize libraries, arrange language-specific state, and run initialization routines before calling application code.
Executable contents also need not be copied into physical memory all at once. Systems using demand paging can bring file-backed memory pages into physical memory as they are accessed.
Filenames, permissions, and compatibility
Filename extensions are conventions rather than a universal definition of executability. Windows commonly uses .exe for application executables, but renaming an arbitrary file with that extension does not create a valid executable. Unix-like systems generally do not require a particular extension; execution depends on file permissions, recognized contents, and system policy.
Execute permission is part of access control, not proof of program validity or trustworthiness. Execution may also be blocked by filesystem mount settings or other security controls.
Compatibility extends beyond the file format. A native program may depend on:
- A particular processor architecture and supported instruction extensions.
- An application binary interface, including calling conventions and data layout.
- Specific operating-system services.
- Compatible runtime libraries and external resources.
Consequently, a correctly formed executable can still fail to start or operate correctly. Emulation and compatibility layers may bridge some differences, but they do not make all executables universally portable.
Security properties
Executing a program gives its instructions access to the resources permitted by its execution context. An executable may therefore perform legitimate work or carry malware. Its extension, icon, or apparent purpose does not establish its behavior.
A digital signature can provide evidence about a file’s integrity and its association with a signing key. It does not by itself establish that the program is harmless or free of defects. A cryptographic hash can identify exact file contents when compared with a trusted expected value, but likewise does not describe what those contents will do.
Systems can restrict executable behavior through sandboxing, permission boundaries, and the principle of least privilege. Memory protections can also separate writable and executable regions. Such controls limit particular capabilities or attack techniques; they do not eliminate every risk from program execution.
The absence of a conventional executable file does not imply the absence of executable behavior. Scripts, document macros, browser-delivered code, and code loaded into an existing process can also cause instructions to run.
Historical development
Early computing systems often loaded programs in relatively simple binary forms. As operating systems developed process isolation, relocatable code, shared libraries, and virtual memory, executable formats acquired richer descriptions of how programs should be loaded.
Older formats included flat binary layouts and the a.out family used by early Unix systems. Formats such as ELF, PE, and Mach-O support more elaborate loading and linking requirements. At the same time, interpreted languages and managed runtimes broadened everyday usage of “executable” beyond files containing native machine instructions.