shell.txt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. SHELL DESIGN NOTES
  2. ------------------
  3. The shell has few bells and whistles. It allows up to 128
  4. backgrounded jobs (after this point you have to wait for some to exit,
  5. because the table it uses to track these cannot be resized.)
  6. The background jobs are tracked in an array of MAXBG pid_t's. If an
  7. open slot is found, a background job's pid can be stashed there.
  8. Background jobs can be collected using the "wait" built-in command,
  9. which removes any pids whose exit status it collects from the
  10. background jobs table.
  11. The wait built-in command takes an optional argument, the process
  12. id to wait for. The shell will attempt to wait for any process, not
  13. just the ones it actually started as its own background jobs. However,
  14. since no facility exists for looking up the pids of running processes,
  15. this ability is not necessarily useful. If no argument is provided,
  16. wait waits for all outstanding background jobs.
  17. The shell uses WNOHANG if WNOHANG is defined, in which case
  18. background jobs are polled after every command, like in Unix shells.
  19. If WNOHANG is not defined, background jobs are polled only by user
  20. request. In OS/161 2.0, WNOHANG is always defined in the kernel header
  21. files, but the implementation is only suggested, not required. To make
  22. the shell stop trying to use WNOHANG, patch it, or remove WNOHANG from
  23. kern/wait.h.
  24. There are two other built-in commands: chdir, which uses the chdir
  25. system call to change directory, and can also be accessed as just cd,
  26. and exit, which causes the shell to exit with a specified exit status
  27. (0 if not supplied).
  28. Note that all these built-in commands must be built into the shell
  29. in order to work usefully.
  30. The shell processes commands by reading lines and then splitting
  31. them up into words using whitespace characters (space, tab, carriage
  32. return, and newline) as separators. No punctuation characters are
  33. interpreted, except for `&'. No variable substitution or argument
  34. wildcard expansion ("globbing") is performed.
  35. The `&' character, if present as the last word on a command line,
  36. is treated as the "background" operator: the command is run as a
  37. background job, that is, after starting it the shell immediately
  38. prints another prompt and accepts more commands. Note that the `&'
  39. must be preceded by whitespace to be recognized. The process id of the
  40. background job is printed as it starts. Note that shell builtins
  41. cannot be backgrounded; furthermore, because the OS/161 console does
  42. not support job control, starting background jobs that perform
  43. terminal input (or, to a lesser extent, terminal output) may produce
  44. confusing and/or unwanted results.
  45. The shell also supports the "sh -c COMMAND" syntax in the hopes
  46. that it will be useful.