magic numbers? (teach me, please)
P. D. Guthrie
pdg at ihdev.UUCP
Wed Nov 27 02:09:54 AEST 1985
In article <124 at rexago1.UUCP> rich at rexago1.UUCP (K. Richard Magill) writes:
>Two questions. I presume they are related. Answers or pointers to doc would
>be appreciated.
>
> 1) How does the shell (exec?) know whether the command I just typed
> is a shell script or one of several possible types of
> executable?
>
The shell doesn't know. The shell merely tells the kernel to exec the
file, after doing a fork. The kernel determines if a file is a binary
executable by the magic number, which is obtained by reading an a.out.h
structure (4.1,4.2) or filehdr.h (sys 5) and comparing it against
hardcoded numbers in the kernel. In 4.1 for instance only 407,413 and
410 are legal. This also tells the kernel the specific type of
executable, and in some cases can set emulation modes. The kernel also
recognizes
#! /your/shellname
at the beginning of a file and execs off the appropriate shell instead.
> 2) Presuming the answer to #1 above has something to do with
> magic numbers, who issues them? is there a common
> (definitive) base of them or does each
> manufacturer/environment make up their own set?
The magic number is issued by the linker/loader. Pretty much the magic
number is decided by the manufacturer, but from what I have seen, is
kept constant over machines. Forgive me if this is wrong, but I do not
have any method of checking, but the magic numbers for say plain
executable 4.x Vax and plain executable SysV.x Vax are the same, but
SysV.x Vax and SysV.x 3B20 are different. Could someone comfirm this?
>
>K. Richard Magill
>(someplace between an advanced user & a guru)
Paul Guthrie
More information about the Comp.unix.wizards
mailing list