Who know the history of unix fork? -
fork great tool in unix.we can use generate our copy , change behaviour.but don't know history of fork.
does can tell me story?
actually, unlike many of basic unix features, fork
relative latecomer (a).
the earliest existence of multiple processes within unix consisted of few (fixed number of) processes, 1 per terminal attached pdp-7 machine (b).
the basic idea shell process given terminal accept command user, locate program file, load small bootstrap program high memory , jump it, passing enough details bootstrap code load program file.
the bootstrap code, after loading program low memory (overwriting shell), jump it.
when program finished, call exit
wasn't exit
know , love today. this exit
reload shell , run using pretty same method used load program in first place.
so more rudimentary exec
command, 1 replaces current program another, in same process space.
the shell exec
program then, when program done, again exec
shell calling exit
.
this method similar found in many other interactive systems @ time, including multics whence unix got name.
from two-way exec
, not big leap adding fork
process duplicator work in conjunction. while many systems run program directly, it's "just add what's needed" method responsible separation of duties between fork
, exec
in unix. resulted in simple fork
function.
if you're interested in history of various features(c) of unix, cannot go past article the evolution of unix time-sharing system
dennis ritchie, presented @ 1979 conference in australia, , subsequently published at&t.
(a) though mean latecomer in sense separation of 4 fundamental forces in universe "late", happening 0.00000000001 seconds after big bang.</humour>.
(b) since question raised in comment how shells started off, there's great resource holding source code unix on @ the unix heritage society, the source code archives and, in particular, first edition.
the init.s
file first edition shows how fixed number of shell processes created (slightly reformatted):
... mov $itab, r1 / address of table r1 1: mov (r1)+, r0 / 'x, x=0, 1... r0 beq 1f / branch if table end movb r0, ttyx+8 / put symbol in ttyx jsr pc, dfork / go make new init ttyx mov r0, (r1)+ / save child id in word offer '0, '1, etc br 1b / set next child 1: ... itab: '0; .. '1; .. '2; .. '3; .. '4; .. '5; .. '6; .. '7; .. 0
here can see snippet creates processes each connected terminal. these days of hard-coded values, no auto detection of terminal quantity involved. zero-terminated table @ itab
used create number of processes , comments code explain how (the possibly tricky bit labels - though there multiple 1
labels, branch nearest 1 in given direction, hence 1b
means closest 1
label in backwards direction).
the code shown processes table, calling dfork
create process each terminal , start getty
, login prompt. getty
program, in turn, started shell. point, it's described in main part of answer.
(c) no paths (and use of temporary links around limitation), limited processes, why there's gecos field in password file, , sorts of other trivia, interesting uber-geeks, of course.
Comments
Post a Comment