Anatomy of a Command Shell


In most systems, user programs and system programs are executed by the command-language interpreter. In more sophisticated systems such as UNIX, there are no major distinctions between this interpreter and any other program — so users can easily create their own shells.

The shell actually executes a command by completing a fork, after which the child process executes an execve (load and execute) of the command. The parent process (the shell) does a wait and suspends its own execution until the child process finishes executing and performs an exit. In multi-tasking systems, such as UNIX, both the shell and the command it is processing can execute concurrently. Users can initiate concurrent execution by typing a command followed by an ampersand. The shell interprets this symbol as an indication not to perform the wait; instead the shell continues with the next step in its command input by prompting the user for the next command.

This capability implies the existence of a fairly sophisticated interprocess communication system. As a bare minimum, a child process needs a method to signal its termination to the parent process (the shell), which is not necessarily polling for this signal.