OILS / doc / process-model.md View on Github | oilshell.org

90 lines, 55 significant
1---
2in_progress: yes
3---
4
5Process Model
6=============
7
8Why does a Unix shell start processes? How many processes are started?
9
10Related: [Interpreter State](interpreter-state.html). These two docs are the
11missing documentation for shell!
12
13<div id="toc">
14</div>
15
16## Shell Constructs That Start Processes
17
18### Pipelines
19
20- `shopt -s lastpipe`
21- `set -o pipefail`
22
23#### Functions Can Be Transparently Put in Pipelines
24
25Implicit subshell:
26
27 { echo 1; echo 2; } | wc -l
28
29A `SubProgramThunk` is started for the LHS of `|`.
30
31### Command Sub `d=$(date)`
32
33 d=$(date)
34
35### Process Sub `<(sort left.txt)`
36
37 diff -u <(sort left.txt) <(sort right.txt)
38
39### Async - `fork` or `sleep 2 &`
40
41### Explicit Subshell - `forkwait` or `( echo hi )`
42
43Explicit Subshells are Rarely Needed.
44
45- prefer `pushd` / `popd`, or `cd { }` in YSH.
46
47## Process Optimizations - `noforklast`
48
49Bugs / issues
50
51- job control:
52 - restoring process state after the shell runs
53 - `sh -i -c 'echo hi'`
54- traps
55 - not run - issue #1853
56- Bug with `set -o pipefail`
57 - likewise we have to disable process optimizations for `! false` and
58 `! false | true`
59
60Oils/YSH specific:
61
62- `shopt -s verbose_errexit`
63- crash dump
64 - because we don't get to test if it failed
65- stats / tracing - counting exit codes
66
67## Process State
68
69### Redirects
70
71
72## Builtins
73
74### [wait]($help)
75
76### [fg]($help)
77
78### [bg]($help)
79
80### [trap]($help)
81
82
83## Appendix: Non-Shell Tools
84
85- `xargs` and `xargs -P`
86- `find -exec`
87- `make -j`
88 - doesn't do anything smart with output
89- `ninja`
90 - buffers output too