Outline



Interactive Shells



What is in the operating system?



Command-Line Shell Implementation

  1. read one line of text
  2. parse the line of text, and perhaps return to step (1) if additional lines are to be parsed (e.g. bash has commands spanning many lines)
  3. interpret the input text to decide what needs to be done
  4. ask the operating system to execute commands as needed, providing the parameters and any other information
  5. internal commands are executed directly by the shell program, rather than resulting in the OS loading an executable file, e.g. exit
  6. while this process is usually interactive, the shell will work exactly the same if given input from a file -- a shell script
  7. the shell is a regular program, usually written in C but could be written e.g. in scheme (scsh) or in any other language



Starting a program in Unix

  1. main is given a count of arguments and an array of pointers to arguments, of which the first is the command name
  2. the system call execv takes as its arguments a command file name and an array of pointers to null-terminated strings containing the arguments
  3. execv destroys the memory copy of the currently running program (the program that called execv) and in its place copies the contents of the executable file -- this is called an overlay
  4. once the overlay is done, execv begins execution of the new program
  5. because of the overlay, a successful call to execv never returns
  6. therefore, a shell forks a child process which is responsible for executing the command
  7. the shell then usually waits for the child process to complete



Processes in Unix



Creating a new process



Sharing among processes



Pipes



Project 1



Shell scripts



A design principle


Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.