Information Technology Reference
In-Depth Information
Executing “untyped” files
Usually, an operating system treats a file's data as an array of untyped bytes, leaving
it up to applications to interpret a file's contents. Occasionally, however, the operating
system needs to be able to parse a file's data.
For example, Linux supports a number of different executable file types such as the
ELF and a.out binary files and tsch, csh, and perl scripts. You can run any of these files
from the command line or using the exec() system call. E.g.,
>a.out
Helloworldfromhello.ccompiledbygcc!
>hello.pl
Helloworldfromhello.pl,aperlscript!
>echo``Helloworldfrom/bin/echo,abinarysuppliedwithyoursystem!''
Helloworldfrom/bin/echo,abinarysuppliedwithyoursystem!
To execute a file, the operating system must determine whether it is a binary file or a
script. If it is the former, the operating system must parse the file to determine where in
the target process's memory to load code and data from the file and which instruction
to start with. If it is the latter, the operating system must determine which interpreter
program it should launch to execute the script.
Linux does this by having executable files begin with a magic number that identifies
the file's format. For example, ELF binary executables begin with the four bytes 0x7f ,
0x45 , 0x4c , and 0x46 (the ASCII characters DEL , E , L , and F ); once an executable is
known to be an ELF file, the ELF standard defines how the operating system should
parse the rest of the file to extract and load the program's code and data. Similarly,
script files begin with #! followed by the name of the interpreter that should be used to
run the script (e.g., a script might begin with #!/bin/sh to be executed using the Bourne
shell or #!/usr/bin/perl to be executed using the perl interpreter.
Alternative approaches include determining a file's type by its name extension—the
characters after the last dot (.) in the file's name (e.g., .exe, .pl, or .sh)—or including
information about a file's type in its metadata.
Search WWH ::




Custom Search