next up previous contents
Next: ELF Up: Processes Previous: Times and Timers

Executing Programs

  In Linux, as in UNIX, programs and commands are normally executed by a command interpreter. A command interpretter is a user process like any other process and is called a shell gif.     There are many shells in Linux, some of the most popular are sh, bash and tsch. With the exception of a few built in commands, such as cd  and pwd , a command is an executable binary file. For each command entered, the shell searches the directories in the processes search path, held in the PATH environment variable, for an executable image with a matching name. If the file is found it is loaded and executed. The shell clones itself using the fork mechanism described above and then the new child process replaces the binary image that it was executing, the shell, with the contents of the executable image file just found. Normally the shell waits for the command to to complete, or rather for the child process to exit. You can cause the shell to run again by pushing the child process to the background by typing control-Z causes a SIGSTOP signal to be sent to the child process, stopping it. You then use the shell command bg  to push it into a background, the shell sends it a SIGCONT signal to restart it, where it will stay until either it ends or it needs to do terminal input or output.

An executable file can have many formats or even be a script file. Script files have to be recognized and the appropriate interpreter run to handle them; for example /bin/sh interprets shell scripts. Executable object files contain executable code and data together with enough information to allow the operating system to load them into memory and execute them. The most commonly used object file format used by Linux is ELF but, in theory, Linux is flexible enough to handle almost any object file format.

   figure4476
Figure: Registered Binary Formats

As with file systems, the binary formats supported by Linux are either built into the kernel are kernel build time or available to be loaded as modules. The kernel keeps a list of supported binary formats (see figure gif) and when an attempt is made to execute a file is made, each binary format is tried in turn until one works.

Commonly supported Linux binary formats are a.out and ELF. Executable files do not have to be read completely into memory, a technique known as demand loading  is used. As each part of the executable image is used by a process it is brought into memory. Unused parts of the image may be discarded from memory.




next up previous contents
Next: ELF Up: Processes Previous: Times and Timers

David A. Rusling
david.rusling@reo.mts.dec.com