^C, ^Z, jobs and fg
Watch / jobs
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.
Process control on a 6502. A long pipeline is killed with ^C and the shell is back at once; ps shows the same processes as before, so nothing is left behind. Then vi is suspended with ^Z, jobs names it, and fg puts it back with its text intact.
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 $ ps $ sleep 60 | sleep 60 > /dev/null & $ ps $ fg keys: <^C> $ ps $ vi notes keys: ihello from the editor<ESC><^Z> $ jobs $ fg keys: :wq<RET> $ cat notes
Between steps it presses ^L to clear the screen.
What the captions say
- Job control. V7 Unix had none.
- Jim Kulp added it to csh; 4.1BSD shipped it in 1981.
- First, what is running now.
- Start a pipeline that will not finish soon, in the background.
- fg brings it to the front. ^C.
- Now an editor. ^Z stops it and gives the shell back.
- jobs lists it; fg brings it back, text intact.
- A shell, a job table, signals, on a 1 MHz 65C02.
The gate that proves it
This film is made by site/demos/jobs.py. Run as assertions, the
same file is make check-demo-jobs, and it runs with the rest of the tests. It requires that ps lists exactly two more processes, children of the shell, once the pipeline is started; that the pipeline is in the foreground, with no prompt, after fg; that after ^C ps lists exactly the processes it listed at the start; that the shell reports the editor Stopped and jobs names it; that the buffer is back on the screen after fg; and that the text survived into the saved file. The checks themselves were tested: with sleep replaced by a copy of true the demo fails at "ps now lists two more processes"; with vi replaced by true it fails at "vi is up".
Transcript
The screen at every checkpoint the test checks, as the recorder saved it:
== ps before (t=14.0 s) $ cd /tmp $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps $ == ps lists the shell and its friends (t=14.0 s) $ cd /tmp $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps $ == ps during (t=28.3 s) $ sleep 60 | sleep 60 > /dev/null & [1] 7 $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps 6 S 06 3 sleep 60 7 S 07 3 sleep 60 $ == ps now lists two more processes: the two sleeps (t=28.3 s) $ sleep 60 | sleep 60 > /dev/null & [1] 7 $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps 6 S 06 3 sleep 60 7 S 07 3 sleep 60 $ == both are children of the shell that started them (t=28.3 s) $ sleep 60 | sleep 60 > /dev/null & [1] 7 $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps 6 S 06 3 sleep 60 7 S 07 3 sleep 60 $ == the pipeline is in the foreground: no prompt yet (t=36.7 s) $ fg sleep 60 | sleep 60 == ps after (t=38.3 s) $ fg sleep 60 | sleep 60 ^C $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps $ == the same processes as before: both sleeps are gone (t=38.3 s) $ fg sleep 60 | sleep 60 ^C $ ps PID S BANK PPID COMMAND 1 S 01 0 [init] 2 R 02 0 [idle] 3 S 03 1 sh 5 R 05 3 ps $ == the shell says the editor is Stopped (t=54.0 s) $ vi notes [1]+ Stopped vi notes $ == jobs names the editor (t=60.4 s) $ vi notes [1]+ Stopped vi notes $ jobs [1]+ Stopped vi notes $ == the text survived ^Z and fg (t=67.3 s) $ vi notes [1]+ Stopped vi notes $ jobs [1]+ Stopped vi notes $ fg vi notes $ cat notes hello from the editor $