Stop vi, run make, carry on
Watch / stopvi
Filmed on the Apple IIe 80-column display. The same session on the Videx UltraTerm: same keys, same text.
The Videx UltraTerm was an 80-column video card for the Apple IIe, with its own video memory and character generator, real hardware scrolling and more screen modes than the IIe's own 80 columns. This demo runs on either display; the UltraTerm film shows the original Videx UltraTerm, emulated.
Job control and virtual consoles, together, on a small project.
The film opens hello.s from the hello example in vi and
makes an edit it does not save. ^Z stops vi, and
make starts in the background. While it builds, chvt 2 moves
to a second console, where ps shows vi stopped and
make running, each in a bank of its own. Back on console 1,
fg returns to vi with the buffer and the cursor where they
were, the edit is saved, and make builds the new program.
What it types
Everything it types, in order. A line starting with $ is a command at the shell, RET included; keys lines are single keystrokes to a program (RET, ESC and the control keys are named).
$ cd /tmp $ mkdir proj; cd proj $ cp /usr/src/examples/HELLO/hello.s /usr/src/examples/HELLO/Makefile . $ vi hello.s keys: G/world<RET>ea, again<ESC><^Z> $ ps > ps.txt $ cut -c1-16 ps.txt | grep -v ' 1$' $ make > build.log 2>&1 & $ jobs $ chvt 2 $ ps > ps2.txt $ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$' $ cut -c1-16 ps2.txt | grep -c ' 11$' $ cut -c1-16 ps2.txt | grep ' 11$' | cut -c6 $ chvt 1 $ wait $ cat build.log $ ./hello $ fg %1 keys: a.<ESC>:wq<RET> $ tail -1 hello.s $ make $ make clean $ make $ ./hello $ make love
What the captions say
- Job control and two consoles, on a real project.
- Bill Joy wrote vi and csh. Jim Kulp gave csh its ^Z.
- A small project: hello.s and its Makefile. Open the source.
- Change the greeting. The edit is in vi, not on the disk yet.
- ^Z stops vi and gives the shell back.
- cut keeps the four fixed columns, grep drops the two console shells: a shell is R or S depending on the instant ps looks.
- The T is vi, stopped, in a bank of its own.
- make, in the background, with its output in a file.
- Then chvt 2, a second console, while it builds.
- vi stopped; make waiting on its child, which runs.
- chvt 1: back where the shell is.
- wait holds the shell until make is done.
- The old greeting. make read the disk; vi's edit was not there.
- fg, and vi is back as it was.
- The cursor is where it was too: append a full stop here.
- Now make again, to pick up the edit.
- This film runs with no clock card, so every file has one date.
- With one, ProDOS still dates only to the minute.
- Either way make sees nothing. So: clean first.
- The old joke: make love. V7's make answered: Don't know how to make love. Stop.
Why make runs in the background
A make run in the foreground would hold console 1, and
chvt is a program: it has to be typed at a shell prompt, and there is no
hotkey. So the film starts make as a job, with its output in a file,
and the shell gives the prompt back at once. jobs lists
vi stopped and make running. The film reads the
process numbers off the screen: the one the
shell printed when it started make, and the stopped process that
ps showed on console 1 before make began. (The film sends ps to a file and filters out the two console shells with grep, because a shell's state at the instant ps looks can be running or waiting, and a recording must say the same on both displays.)
What make saw
make reads the disk, and the edit was still only in vi's
buffer, so the first build is the old program and says
hello, world. The new one, built after the save, says
hello, world, again. Afterwards a plain make prints nothing. The film runs with the clock
card switched off, so that every recording is the same, and every file has one date.
With a clock card ProDOS would still date files only to the minute, and
make treats an equal date as not newer; the edit comes about 50 seconds
after the build, so it would be invisible to make either way. The film
runs make clean first.
The gate that proves it
This film is made by site/demos/stopvi.py. Run as assertions, the
same file is make check-demo-stopvi, and it runs with the rest of the tests, on both displays. It requires that
the shell reports vi Stopped and jobs lists it beside the
running make; that ps on console 2 holds the process that was
stopped, still stopped, and the process the shell numbered for make, in
the bank that is its process number, with a child of its own; that console 1, when
it is switched back to, is exactly as it was left; that the log make
wrote while vi was stopped is the old build and that program says the
old greeting; that after fg the same rows are on the screen as before
^Z and a full stop typed there lands right after the edit; that the saved
file holds both; that a plain make after the save prints nothing; and that the rebuilt program says the new greeting. No label in the
gate holds a process number or any timing. The checks themselves were tested: with make replaced by a copy of true it fails at "jobs lists vi stopped and make running"; with chvt replaced by true it fails at "console 2 is a fresh, blank screen with a prompt".
Transcript
The screen at every checkpoint the test checks, as the recorder saved it:
== host: hello.s ends with the greeting line (t=0.0 s)
$
== host: the edits change the line (t=0.0 s)
$
== cp prints nothing (t=24.9 s)
$ cd /tmp
$ mkdir proj; cd proj
$ cp /usr/src/examples/HELLO/hello.s /usr/src/examples/HELLO/Makefile .
$
== the buffer holds the edited greeting, on its last line (t=45.4 s)
*
* This file is staged on the release disk as MAUX TEXT (high
* bit set, lines ended by $8D), exactly what `vi` writes. nas
* reads that or ProDOS-standard text (low ASCII, $0D) alike, so
* edit it with `vi` and run `nas` on it: nothing to convert.
*---------------------------------------------------------------
rel
lst off
PUTS ext
EXIT ext
put /usr/inc/sc.fd.equ
put /usr/inc/zp.equ
START lda #<MSG
sta PTR0
lda #>MSG
sta PTR0+1
ldx #FD_STDOUT
jsr PUTS
lda #0
jsr EXIT
MSG asc 'hello, world, again',0D,00
/world
== the shell says vi is Stopped (t=49.6 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$
== ps prints nothing to the screen (t=52.3 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$
== ps with vi stopped (t=66.7 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$
== ps shows one stopped process, in the bank that is its PID (t=66.7 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$
== the shell prints the job number and PID (t=84.3 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$ make > build.log 2>&1 &
[2] 11
$
== jobs lists vi stopped and make running (t=86.5 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$ make > build.log 2>&1 &
[2] 11
$ jobs
[1]- Stopped vi hello.s
[2]+ Running make
$
== host: console 1 sits at a prompt (t=86.5 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$ make > build.log 2>&1 &
[2] 11
$ jobs
[1]- Stopped vi hello.s
[2]+ Running make
$
== console 2 is a fresh, blank screen with a prompt (t=90.9 s)
$
== ps prints nothing to the screen (t=94.3 s)
$ ps > ps2.txt
$
== host: make took pid 11, the one the ps filters name (t=94.3 s)
$ ps > ps2.txt
$
== ps on console 2 (t=103.8 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$
== ps lists distinct processes, each in the bank that is its PID (t=103.8 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$
== vi is still there, stopped (t=103.8 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$
== make itself is blocked, waiting (t=103.8 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$
== make has exactly one child (t=110.9 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$ cut -c1-16 ps2.txt | grep -c ' 11$'
1
$
== that child is running (t=119.1 s)
$ ps > ps2.txt
$ cut -c1-16 ps2.txt | grep -v ' 1$' | grep -v ' 11$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 14
11 S 0B 3
$ cut -c1-16 ps2.txt | grep -c ' 11$'
1
$ cut -c1-16 ps2.txt | grep ' 11$' | cut -c6
R
$
== console 1 is back: its rows as left, then chvt 2 and a fresh prompt (t=128.4 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$ make > build.log 2>&1 &
[2] 11
$ jobs
[1]- Stopped vi hello.s
[2]+ Running make
$ chvt 2
$
== wait prints nothing (t=133.4 s)
$ vi hello.s
[1]+ Stopped vi hello.s
$ ps > ps.txt
$ cut -c1-16 ps.txt | grep -v ' 1$'
PID S BANK PPID
1 S 01 0
2 R 02 0
7 T 07 3
8 R 08 3
$ make > build.log 2>&1 &
[2] 11
$ jobs
[1]- Stopped vi hello.s
[2]+ Running make
$ chvt 2
$ wait
$
== build.log has the three lines (t=136.6 s)
$ cat build.log
nas -o hello.o hello.s
nas: 32 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== build.log reads in order: make built hello while vi was stopped (t=136.6 s)
$ cat build.log
nas -o hello.o hello.s
nas: 32 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== the first build says the OLD greeting (t=138.6 s)
$ cat build.log
nas -o hello.o hello.s
nas: 32 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$ ./hello
hello, world
$
== vi shows the same rows it showed before ^Z (t=151.0 s)
*
* This file is staged on the release disk as MAUX TEXT (high
* bit set, lines ended by $8D), exactly what `vi` writes. nas
* reads that or ProDOS-standard text (low ASCII, $0D) alike, so
* edit it with `vi` and run `nas` on it: nothing to convert.
*---------------------------------------------------------------
rel
lst off
PUTS ext
EXIT ext
put /usr/inc/sc.fd.equ
put /usr/inc/zp.equ
START lda #<MSG
sta PTR0
lda #>MSG
sta PTR0+1
ldx #FD_STDOUT
jsr PUTS
lda #0
jsr EXIT
MSG asc 'hello, world, again',0D,00
== the file holds the edit and the full stop (t=163.9 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$
== make says nothing: the edit is not newer (t=169.1 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$
== make clean removes the outputs (t=185.5 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$ make clean
rm -f hello hello.o
$
== make rebuilds (t=188.5 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$ make clean
rm -f hello hello.o
$ make
nas -o hello.o hello.s
nas: 40 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== make assembles with nas, then links (t=188.5 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$ make clean
rm -f hello hello.o
$ make
nas -o hello.o hello.s
nas: 40 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== the new build says the new greeting (t=190.4 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$ make clean
rm -f hello hello.o
$ make
nas -o hello.o hello.s
nas: 40 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$ ./hello
hello, world, again.
$
== make has no rule for love either (t=198.5 s)
$ tail -1 hello.s
MSG asc 'hello, world, again.',0D,00
$ make
$ make clean
rm -f hello hello.o
$ make
nas -o hello.o hello.s
nas: 40 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$ ./hello
hello, world, again.
$ make love
make: no rule to make target love
$