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