Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 exptools; site ihdev.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!ihdev!pdg From: pdg@ihdev.UUCP (P. D. Guthrie) Newsgroups: net.unix-wizards Subject: Re: magic numbers? (teach me, please) Message-ID: <416@ihdev.UUCP> Date: Tue, 26-Nov-85 11:09:54 EST Article-I.D.: ihdev.416 Posted: Tue Nov 26 11:09:54 1985 Date-Received: Wed, 27-Nov-85 06:07:13 EST References: <124@rexago1.UUCP> Reply-To: pdg@ihdev.UUCP (55224-P. D. Guthrie) Distribution: net Organization: AT&T Bell Laboratories Lines: 37 In article <124@rexago1.UUCP> rich@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