Полезная информация

next up previous contents
Next: Accessing filesystems Up: Tour of the kernel Previous: Creating and destroying processes

Executing programs

After fork()ing, two copies of the same program are running. One of them usually exec()s another program. The exec() system call must locate the binary image of the executable file, load and run it. The word `load' doesn't necessarily mean ``copy in memory the binary image'', as supports demand loading.

The implementation of exec() supports different binary formats. This is accomplished through the linux_binfmt structure, which embeds two pointers to functions--one to load the executable and the other to load the library, each binary format representing both the executable and the library. Loading of shared libraries is implemented in the same source file as exec() is, but let's stick to exec() itself.

The systems provide the programmer with six flavours of the exec() function. All but one of them can be implemented as library functions, and the kernel implements sys_execve() alone. It performs quite a simple task: loading the head of the executable, and trying to execute it. If the first two bytes are ``#!'', then the first line is parsed and an interpreter is invoked, otherwise the registered binary formats are sequentially tried.

The native format is supported directly within fs/exec.c, and the relevant functions are load_aout_binary and load_aout_library. As for the binaries, the function loading an a.out executable ends up either in mmap()ing the disk file, or in calling read_exec(). The former way uses the demand loading mechanism to fault-in program pages when they're accessed, while the latter way is used when memory mapping is not supported by the host filesystem (for example the ``msdos'' filesystem).

tex2html_wrap2945



Converted on:
Mon Apr 1 10:20:16 EST 1996