UnixEditionZero OCR

Embed Size (px)

Citation preview

  • 8/17/2019 UnixEditionZero OCR

    1/53

    q7. .

    i...

    DRAFT

    The UNIX Time-Sha. r ing System

    D. M R i t c h i e

    I n t r o d u c t i o n

    UNIX i s a gene ra l -pu rpose , m u l t i - u s e r t i m e s h a r i n g sys tem im -

    \ plernented on s e v e r a l D i g i t a l E q u i p ~ a n tC o r p o r a t i o n PDF s e r i e ~

    machines .

    UNIX was w r i t t e n by K. L. Tho::ipson, who a l s o w r o t e many o f t f :e

    command programs. The a u t h o r o f t h i s meraorandum c o n t r i b u t e d

    s e v e r a l o f t h e major coramands, i n c l u d i n g t h e a s s e m b l e r and t h e

    debugger. The f i l e sys tem was o r i g i n a l l y d e s i g n e d by Thompson,

    t h e a u t h o r ~ n d R. H. Canaday.

    rhe re a r e two v e r s i o n s o f UNIX. The f i r s t which has been i n e x -

    i s t e n c e abou t a y e a r r t lns on t h e PDP-7 and - 9c o r a p u t ~ r s

    a moremodern v e r s i o n a few months o l d u s e s t h e PDP-11. T h i s docu :r e n t

    d e s c r i b e s U ~ I X - 1 1s ince t i s more modern and many o f t h e d i f -

    f e r e n c e s between t and UNIX-7 r e s u l t from r e d e s i g n o f f e a t u r e s

    found t o be d e f i c i e n t o r l a c k i n g i n t h e e a r l i e r sys tem.

    Al though t h e PDP-7 and PDP-11 a r e b o t h smal l comput e r s t h e

    d e s i g n o f UNIX i s amenable t o e x p a n s i o n f o r u s e on more power fu l

    mach ines . In: ieed, UNIX c o n t a i n s a number o f f e a t u r e s v : : ~ r yse lcom

    o f f e r e d even y l a r g e r s y s t e ~ s i n c l u d i n g

    1o A v e r s a t i l e c o n v e n i e n t f i l e sys tem w i t h comple te i n t e g r a -

    t i o n between d i s k f i l e s and I /O d e v i c e s ;

  • 8/17/2019 UnixEditionZero OCR

    2/53

    ;

    )

    - 2 -

    2 . The a b i l i t y t o i n i t i a t e a s y n c h r o u s l y r u n n i n g p r o c e s s e s .

    I t m u s t be s a i d however t h a t t h e most i m p o r t a n t f e a t u r e s o f

    UNIX a r e i t s s i m p l i c i t y e l e g a n c e and e a s e o f u s e .

    B e s i d e s t h e s y s t e m p r o p e r t h e major p rograms a v a i l a b l e u n d e r

    UNIX a r e an a s s e m b l e r a t e x t e d i t o r b a s e d on QED, a s y m b o l i c

    debugger f o r e x a m i n i n g and p a t c h i n g f a u l t y p r o g r a m s and B a

    h i g h e r l e v e l l anguage r e s e m b l i n g BCPL. UNIX-7 a l s o has a v e r s i o n

    o f t h e c o m p i l e r wri t in i : r l a n g u a g e TMGL c o n t r i b u t e d by M D.

    M c i l r o y and b e s i d e s i t s own a s s e m b l e r t h e r e - t ~i s a PDP-11

    a s s e m b l e r which was u s e d t o w r i t e UNIX-11. On t h e PDP-11 t h e r e i s

    a v e r s i o n o f BASIC · [ r e f e r e n c e ] a d a p t e d f rom t h e one s u p p l i e d y

    DEC [ r e f e r e n c e ] . A l l b u t t h e l a s t o f t h e s e programs were w r i t t e n

    l o c a l l y and e x c e p t f o r t h e v e r y f i r s t v e r s i o n s o f t h e e d i t o r and

    a s s e m b l e r u s i n g UNIX i t s e l f .

    £ Hardware

    The PDP-11 on i ~ h i c hUNIX i s imp lemen ted i s a 1 6 - b i t 1 2K compu te r

    and UNIX o c c u p i e s BK w o r d s . More t h a n h a l f o f t h i s s p a c e

    however i s u t i l i z e d f o r a v a r i a b l e number o f d i s k b u f f e r s ; w i t h

    some l o s s o f s p e e d t h e number o f b u f f e r s cou ld be c u t

    s i g n i f i c a n t l y .

    The PDP-11 h a s a 256K word d i s k a l m o s t a l l o f which i s u s e d f o r

    f i l e s y s t e m s t o r a g e . t i s e q u i p p e d w i t h DECTAPE, a v a r i e t y o f

    m a g n e t i c t a p e f a c i l i t y i n which i n d i v i d u a l r e c o r d s may be a d d r e s -

    sed and r e w r i t t e n a t w i l l . A l s o a v a i l a b l e a r e a h i g h - s p e e d paper

    t a p e r e a d e r and punch . B e s i d e s t h e s t a n d a r d Te l e t y p e t h e r e a r 3

  • 8/17/2019 UnixEditionZero OCR

    3/53

    - 3 -

    s e v e r a l v a r i a b l e - s p e e d communicat ions i n t e r.= a ce s .

    · The F i l e System

    The most i m p o r t a n t r o l e o fUN X

    i s t o p r o v i d e a f i l e sys tem ·. Fromt h e p o i n t o f view o f t h e u s e r , t h e r e a r e t h r e e k i n d s o f f i l e s :

    o r d i n a r y d i s k f i l e s , d i r e c t o r i e s , and s p e c i a l f i l e s .

    -\l · O r d i n a r y F i l e s

    A f i l e c o n t a in s whatever i n fo rma t io n t h e u s e r p l a c e s t h e r e , f o r

    example symbol ic o r b i n a r y ( o b j e c t ) programs . No p a r t i c u l a r

    s t r u c t u r i n g i s e x p e c t e d by t h e sys tem. F i l e s o f t e x t o r d i n a r i l y

    c o n s i s t s imply o f a s t r i n g o f c h a r a c t e r s , wi th l i n e s demarca ted

    by t h e n e w - l i n e c h a r a c t e r . B i n a r y programs a r e sequences o f words

    as t h e y w i l l a p p e a r i n c o r e memory when t h e program s t a r t s

    e x e c u t i n g . A few u s e r programs g e n e r a t e and e x pec t f i l e s wi th

    more s t r u c t u r e ; f o r example , t h e a s s e m b l e r g e n e r a ~ e sand t h e

    debugger e x p e c ~ sa name l s t f i l e i n a p a r t i c u l a r fo rmat ;

    howev e r , t h e s t r u c t u r e o f f i l e s i s c o n t r o l l e d s o l e l y by t h e

    programs which u s e them, n o t by t h e sys tem.

    l · ~ D i r e c t o r i e s

    D ir e c t o r i e s som e t im es c a t a l o g s ) , p r o v i d e t h e mapping betweent h e names o f f i l e s and t h e f i l e s t h e m s e l v e s , and t h u s i nduce a

    s t r u c t u r e on t h e f i l e sys tem as a whole . Each u s e r ha s a d i r e c -

    t o r y o f h i s own f i l e s ; h e ma y a l s o c r e a t e s u b d i r e c t o r i es t o c o n -

    t a i n a,roups o f f i l e s con ven i en t l y t r e a t e d t o g e t h e r .

  • 8/17/2019 UnixEditionZero OCR

    4/53

    - 4 -

    A d i r e c t o r y i s e x a c t l y l i k e an o r d i n a r y f i l e e x c e p t t h a t t c a n -

    n o t be w r i t t e n on y u s e r programs , so t h a t t h e sys tem c o n t r o l s

    t h e c o n t e n t s o f d i r e c t o r i e s . However, anyone w i t h a p p r o p r i a t e

    -- p e r m i s s i o n may r e a d a d i r e c t o r y j u s t l i k e any o t h e r f i l e .

    The s y s t e m m a i n t a i n s s e v e r a l d i r e c t o r i e s f o r i t s own use . one o f

    t h e s e i s t h e r o o t d i r e c t o r y . A l l f i l e s i n t h e sys tem can be found

    by t r a c i n g a p a t h t h r o u g h a c h a i n o f d i r e c t o r i e s u n t i l t h e)

    / d e s i r e d f i l e i s r e a c h e d . The s t a r t i n g p o i n t f o r such s e a r c h e s i s

    o f t e n t h e r o o t , which c o n t a i n s an e n t r y f o r e a c h u s e r ' s maste r

    d i r e c t o r y. Another sys tem d i r e c t o r y c o n t a i n s a l l t h e programs

    p r o v i d e d a s p a r t o f t h e system; t h a t i s , a l l t h e commands

    ( e l s e w h e r e , s u b s y s t e m s ) . As w i l l b e s e e n , however, t i s by no

    means ne ce s sa ry t h a t a program r e s i d e i n t h i s d i r e c t o r y f o r t t o

    be u s e d a s a command.

    F i l e s and d i r e c t o r i e s a r e named by sequences o f e i g h t o r fewer

    c h a r a c t e r s . When t h e name o f a f i l e i s s p e c i f i e d t o t:he sys tem,t may be i u t h e form o f a p a t h ~ which i s a sequence o f

    d i r e c t o r y names s e p a r a t e d by s l a s h e s and e n d i n g i n a f i l e nameo

    I f t h e sequence b e g i n s w i t h a s l a s h , t h e s e a r c h b e g i n s i n t h e

    r o o t d i r e c t o r y . The name / a / b / c c a u s e s t h e sys tem t o s e a r c h t h e

    f o r d i r e c t o r y s e a r c h f o r b ando o t a . t h e n t o a t h e n t of i n d i n be o r d i n a r y f i l e , d i r e c t o r y ,b . c may an a o r a

    /p e c i a l f i l e . As a l i m i t i n g ca se , t h e name r e f e r s t o t h e r o o t

    i t s e l f .

    The same n o n - d i r e c t o r y f i l e may appear i n s e v e r a l d i r e c t o r i e s u n

    d e r p o s s i b l y d i f f e r e n t names . This f e a t u r e i s c a l l e d l i n k i n g ; a

    d i r e c t o r y e n t r y f o r a f i l e i s so:netimes c a l l e d a l i n k . UN X d i f -

  • 8/17/2019 UnixEditionZero OCR

    5/53

    - 5 -

    f e r s f rom o t h e r sys tems i n which l i n k i n g i s p e r m i t t e d i n t h a t a l l

    l i n k s t o a f i l e have e q u a l s t a t u s . T h a t i s , a f i l e does n o t e x -

    i s t w i t h i n a p a r t i c u l a r d i r e c t o r y ; t h e d i r e c t o r y e n t r y f o r a f i l e

    ; c o n s i s t s mere ly o f i t s name and a p o i n t e r t o t h e i n f o r m a t i o n ac--

    )

    t u a l l y d e s c r i b i n g t h e f i l e . Thus a f i l e e x i s t s i n d e p e n d e n t l y o f

    any d i r e c t o r y e n t r y , a l t h oug h i n p r a c t i c e a f i l e i s made t o

    d i s a p p e a r a l o n g w i t h t h e l a s t l i n k t o i t .

    When a u s e r l o g s i n t o UNIX h e i s a s s i g n e d a d e f a u l t c u r r e n t

    d i r e c t o r y , b u t he may change t o any d i r e c t o r y · r e a d a b l e by him. A

    p a t h name n o t s t a r t i n g w i t h / c a u s e s t h e sys tem t o b e g i n t h e

    Thus, t h e name a / be a r c h i n t h e u s e r ' s c u r r e n t d i r e c t o r y .

    s p e c i f i e s t h e f i l e named b i n d i r e c t o r y a , which i s found i n

    t h e c u r r e n t working d i r e c t o r y . The s i m p l e s t k i n d o f name, f o r e x -

    amplet

    a r e f e r s t o a f i l e which i t s e l f i s found i n t h e work ing

    d i r e c t o r y .

    Each d i r e c t o r y always ·has a t l e a s t two e n t r i e s . The ' n a m e . i neach d i r e c t o r y . r e f e r s t o t h e d i r e c t o r y i t s e l f . Thus a program may

    .e a d t h e c u r r e n t d i r e c t o r y under t h e name • w i t h o u t knowin g i t sa c t u a l p a t h name. The name •• by c o n v e n t i o n r e f e r s t o t h e

    _ p a r e n t o f t h e d i r e c t o r y i n which i t a p p e a r s ; t h a t i s , t h e d i r e c

    t o r y i n which i t was f i r s t c r e a t e d .

    The d i r e c t o r y s t r u c t u r e i s c o n s t r a i n e d t o have t h e form o f a

    r o o t e d t r e e . Excep t f o r t h e s p e c i a l e n t r i e s • and . , e a c h)

    d i r e c t o r y must a ppe a r a s an e n t r y i n e x a c t l y one o t h e r , which i s

    i t s pa r e n t . Th e r e a s on f o r t h i s i s t o s im p l i f y t h e w r i t i n g o f

    program s which v i s i t s u b t r e e s o f t h e d i r e c t o r y s t r u c t u r e an d

    mo r e im po r t a n t , t o a v o i d t h e s e p a r a t i o n o f p o r t i o n s o f t h e

  • 8/17/2019 UnixEditionZero OCR

    6/53

    - 6 -

    h i e r a r c h y. I f a r b i t r a r y l i n k s t o d i r e c t o r i e s were p e r m i t t e d t

    would b e q u i t e d i f f i c u l t t o d e t e c t when t h e l a s t c o n n e c t i o n froill

    t h e r o o t t o a d i r e c t o r y was s e v e r e d .

    · S p e c i a l F i l e s

    S p e c i a l f i l e s c o n s t i t u t e t h e most u n u s u a l f e a t u r e o f t h e UN X

    f i l e sys tem. Each I / O dev i c e s u p p o r t e d by UNIX i s a s s o c i a t e d w i t h\J a t l e a s t one s p e c i a l f i l e . S p e c i a l f i l e s a r e r e a d and w r i t t e n

    j u s t l i k e o r d i n a r y d i s k f i l e s , b u t t h e r e s u l t i s a c t i v a t i o n o f

    t h e a s s o c i a t e d dev i ce . E n t r i e s f o r a l l s p e c i a l f i l e s r e s i d e i n

    t h e r o o t d i r e c t o r y , so t h e y may a l l b e r e f e r r e d t o by / f o l -

    lowed by t h e a p p r o p r i a t e name.

    The s p e c i a l f i l e s a r e d i s c u s s e d f u r t h e r i n s e c t i o n 6 below.

    3 • 1 P r o t e c t i o n

    The p r o t e c t i o n scheme i n UN X i s q u i t e s i m p l e . Each u s e r o f t h e

    sys tem i s a s s i g n e d a uniql,.le u s e r number. When a f i l e · i s c r e a t e d ,

    t i s marked w i t h t h e number o f i t s c r e a t o r . Also g i v e n f o r new

    \ f i l e s i s a s e t o f p r o t e c t i o n b i t s . Four o f t h e s e s p e c i f y i n d e p e n -

    d e n t l y p e r m i s s i o n t o r e a d o r w r i t e f o r t h e owner o f t h e f i l e and

    f o r a l l o t h e r u s e r s . A f i f t h b i t i n d i c a t e s p e r m i s s i o n t o ex e c u t e

    t h e f i l e as a program. I f t h e s i x t h b i t i s o n t h e sys tem w i l l

    t e m p o r a r i l y change t h e u s e r i d e n t i f i c a t i o n o f t h e c u r r e n t u s e r t o\

    j t h a t o f t h e c r e a t o r o f t h e f i l e whenever t h e f i l e i s e x e c u t e d a s

    a p ro g r a m. Thi s f e a t u r e p ro v i d e s f o r p r i v i l e ged p r o g r a ms which

    may u s e f i l e s which shou ld n e i t h e r be r e a d nor changed by o t h e r

    u s e r s . I f t h e s e t - u s e r - i d e n t i f i c a t i o n b i t i s on f o r a pro g r a 8 ,

  • 8/17/2019 UnixEditionZero OCR

    7/53

    - 7 -

    t h e a c c o u n t i n g f i l e may be a c c e s s e d du r i n g t h e p r o g r a m ' s e x e c u -

    t i o n b u t n o t o t h e r w i s e .

    - ~ ~System I /Q C a l l s

    The sys tem c a l l s t o do I /O a r e d e s i g n e d t o e l i m i n a t e t h e d i f -

    e r ence s between t h e v a r i o u s d ev i ce s and s t y l e s o f a c c e s s . There

    i s no d i s t i n c t i o n between random and s e q u e n t i a l I / O , n o r i s any

    l o g i c a l o r p h y s i c a l r e c o r d s i z e imposed by t h e sys tem. The s i z e

    o f a f i l e on t h e d i s k i s d e t e r m i n e d by t h e l o c a t i o n o f t h e l a s t

    p i e c e o f i n f o r m a t i o n w r i t t e n on i t no p r e d e t e r m i n a t i o n o f t h e

    s i z e o f a f i l e i s neces s a r y. I n UNIX-11, t h e u n i t o f i n f o r m a t i o n

    i s t h e 8 - b i t b y t e s i n c e t h e PDP-11 i s a b y t e - o r i e n t e d machine .

    To i l l u s t r a t e t h e e s s e n t i a l s o f I /O i n UNIX, t h e b a s i c c a l l s a r e

    summarized below i n an anonymous h i g h e r l e v e l languac:;re which w i l l

    i n d i c a t e t h e needed param e t e r s w i t h o u t g e t t i n g i n t o t h e com p l e x -

    i t i e s o f machine l anguage prograrmning. (A l l sys tem e a r l s a r e a l s od e s c r i b e d i n .Appendix 1 i n t h e i r a c t u a l f o r m . ) Each c a l l t o t h e

    sys tem may p o t e n t i a l l y r e s u l t i n an e r r o r r e t u r n which f o r s i m -

    p l i c i t y i s n o t r e p r e s e n t e d i n t h e c a l l i n g s e quence .

    To r e a d o r w r i t e a f i l e assumed t o e x i s t a l r e a d y i t must be

    opened by t h e f o l l owin g c a l l :

    f i l ep = o pe n(nam e , f l a g

    N e i n d i c a t e s t h e name o f t h e f i l e . An a r b i t r a r y p a t h name ma y

    be g i v e n. Th e f l a c a r g ument i n d i c a t e s wheth e r t h e f i l e i s t o b e

  • 8/17/2019 UnixEditionZero OCR

    8/53

    - 8 -

    H H

    r e a d o r w r i t t e n . I f t h e f i l e i s t o be u p d a t e d t h a t i s r e a d and

    w r i t t e n s i m u l t a n e o u s l y, i t may be opened t w i c e , once f o r r e ad ing

    and once f o r w r i t i n g .

    The r e t u r n e d arcrument f i l e p i s c a l l e d a f i l e d e s c r i p t o r . I t i s

    used t o i d e n t i f y t h e f i l e i n subsequen t c a l l s t o r e ad , w r i t e o r

    o the rw i se m a n i p u l a t e t h e f i l e .

    There a r e no l o c k s i n t h e f i l e sys tem, n o r i s t h e r e any r e s t r i c

    t i o n on t h e number o f u s e r s who may have a f i l e open f o r r e ad ing

    o r w r i t i n g . Although one may imagine s i t u a t i o n s i n which t h i s

    f a c t i s u n f o r t u n a t e , i n p r a c t i c e d i f f i c u l t i e s a r e q u i t e r a r e .

    3 • .2 .l C r e a t e

    To c r e a t e a new f i l e , t h e f o l l o w i n g c a l l i s u s e d .

    f i l e p = c r e a t e n a m e , mode)

    Here f i l e p and name a r e a s b e f o r e . I f t h e f i l e a l r e a d y e x i s t e d ,

    i t i s t r u n c a t e d t o zero l e n g t h . C r e a t i o n o f a f t l e i m p l i e s

    open ing f o r w r i t i n g as w e l l . The mode argument i n d i c a t e s t h e p e r -

    m i s s i o n s which a r e t o be p l a c e d on t h e f i l e y t h e p r o t e c t i o n

    mechanism. To c r e a t e a fil

  • 8/17/2019 UnixEditionZero OCR

    9/53

    - 9 -

    t h e f i r s t f o l l o w i n g by t e . For e a c h open f i l e t h e r e i s a p o i n t e r ,

    m a i n t a i n e d y t h e sys tem, which always i n d i c a t e s t h e n e x t b y t e t o

    be r e ad o r w r i t t e n . I f n b y t e s a r e r e a d , t h e p o i n t e r advc>.nces y

    - n b y t e s .

    Once a f i l e i s open f o r w r i t i n g , t h e f o l l o w i n g c a l l may be u s e d .

    n w r i t t e n = w r i t e f i l e p , b u f f e r , count )

    B u ff e r i s t h e a d d r e s s o f coun t s e q u e n t i a l l y s t o r e d by t e s words

    i n UNIX-7) which w i l l be w r i t t e n o n t o t h e f i l e . n w r i t t e n i s t h e

    number o f b y t e s a c t u a l l y w r i t t e n ; e x c e p t i n r a r e c a s e s t i s t h e

    same a s c o u n t . O c c a s i o n a l l y, an e r r o r may be i n d i c a t e d ; f o r exar. ,-

    p l e i f p a p e r t ape i s b e i n g w r i t t e n , an e r r o r o c c u r s i f t h e t a p e

    r u n s o u t .

    For d i s k f i l e s which a l r e a d y e x i s t e d t h a t i s , were opened by

    open, n o t c r e a t e ) t h e by t e s w r i t t e n a f f e c t on l y t hose impl ied by

    t h e p o s i t i o n o f t h e . w r i t e p o i n t e r and t h e number o f b y t e s

    w r i t t e n ; no o t h e r p a r t o f t h e f i l e i s changed .

    To re ad , t h e c a l l i s_ /

    n r e a d = r e a d f i l e p , b u f f e r , c o u n t )

    p t o coun t b y t e s a r e r e a d f rom t h e f i l e i n t o b u f f e r . The number

    a c t u a l l y r e a d i s r e t u r n e d a s n r e a d . Every program must be_ j

    p r e p a r e d f o r t h e p o s s i b i l i t y t h a t n r e ~ i s l e s s t h a n coun t . I f

    t h e r e a d p o i n t e r i s so n e a r t h e end o f t h e f i l e t h a t r e ad ing

    count c h a r a c t e r s would cause r e a d i n g beyond t h e end , o n l y s u f -

  • 8/17/2019 UnixEditionZero OCR

    10/53

    - 10 -

    f i c i e n t by t e s a r e t r a n s m i t t e d t o r e ach t h e end o f t h e f i l e .

    F u r t h e r m o r e d e v i c e s l i k e t h e t y p e w r i t e r s work i n u n i t s o f l i n e s .

    Suppose f o r example t h a t b e f o r e a n y t h i n g has been typed a

    program t r i e s t o r e a d 2 8 c h a r a c t e r s from t h e conso l e . This f o r

    c e s t h e program t o w a i t s i n c e n o t h i n g h a s been typed . The u s e r

    now t y p e s a l i n e c o n s i s t i n g , s ay o f 10 c h a r a c t e r s and h i t s t he

    new 1. ..i n e key. At t h i s p o i n t t h e r e ad c a l l would r e t u r n i n -

    d i c a t i n g 11 c h a r a c t e r s r e a d i n c l u d i n g t h e new l i n e ) . On t h e

    o t h e r hand i t i s pe rmis s ib l e t o r e a d f ewer c h a r a c t e r s t h a n were

    typed wi t h ou t l o s i n g i n fo rma t io n ; f o r example by te s may be p i c k e d

    u p one a t a t i m e .

    When t h e r e a d c a l l r e t u r n s w i t h n r e a d e q u a l t o z e r o i t i n d i c a t e s

    t h e end o f t he f i l e . For d i s k f i l e s t h i s o c c u r s when t h e r e a d

    p o i n t e r becomes e q u a l t o t h e c u r r e n t s i z e o f t h e f i l e . t i s pos -

    s i b l e t o gene ra t e an e n d - o f - f i l e f rom a t y p e w r i t e r by use o f an

    e s c a p e sequence which depends on t h e dev i ce u s e d .

    2.·2·2 Seel<

    To do andom , t h a t i s , d i r e c t acce s s I /O i t i s o n l y n e c e s s a r y

    t o move t he r e a d o r w r i t e p o i n t e r t o t h e a p p r o p r i a t e l o c a t i o n i n

    t h e f i l e .

    s e e k f i l ep , bas e , o f f s e t )

    The r e a d p o i n t e r r e s p e c t i v e l y w r i t e p o i n t e r ) a s s o c i a t e d wi t h

    f i l e n i s moved t o a p o s i t i o n o ~ s words f r o m t h e b e g i n n i n ]

    f rom t h e c u r r e n t p o s i t i o n o f t h e p o i n t e r , o r from t h e end o f t h e

    f i l e , depending on whether b a s e i s o 1 o r 2 . O f f s e t may ;:e

  • 8/17/2019 UnixEditionZero OCR

    11/53

    - 11 -

    n e g a t i v e t o move t h e p o i n t e r backwards . o r some d e v i c e s e . g .

    p a p e r t a p e and t y p e w r i t e r s ) s e e k c a l l s a r e m e a n i n g l e s s and a r e

    i g n o r e d .

    The c u r r e n t p o s i t i o n o f t h e p o i n t e r may be d i s c o v e r e d as f o l l o w s :

    o f f s e t = t e l l f i l e p , b a s e

    As w i t h s e e k , f i lAD i s t h e f i l e d e s c r i p t o r f o r an open f i l e , and

    b a s e s p e c i f i e s whethe r t h e d e s i r e d o f f s e t i s t o be measured f rom

    t h e b e g i n n i n g o f t h e f i l e , f rom t h e c u r r e n t p o s i t i o n o f t h e p o i n

    t e r , o r f rom t h e end . In t h e second c a s e , o f c o u r s e , t h e r e s u l t

    i s a lways z e r o .

    4 . I m p l e m e n t a t i o n o f t h e F i l e System

    As ment ioned i n s e c t i o n 3 . 2 above , a d i r e c t o r y e n t r y c o n t a i n s

    o n l y a name f o r t h e a s s o c i a t e d f i l e and a p o i n t e r t o t h e f i l e

    i t s e l f . Th i s p o i n t e r i s an i n t e g e r c a l l e d t h e i n u m b e ~f o r i d e n

    t i f i c a t i o n number o f t h e f i l e . When t h e f i l e i s a c c e s s e d , i t s i - .

    number i s l ooked up i n a s.ystem t a b l e s t o r e d i n a known p a r t o f

    t h e d i s k . The e n t r y t h e r e b y found t h e f i l e s i - n o d e ) c o n t a i n 3

    t h e d e G c r i p t i o n o f t h e f i l e :

    1 . i t s owner ;

    2 . i t s p r o t e c t i o n b i t s ;

    3 . t h e p h y s i c a l d i s k a d d r e s s e s f o r t h e f i l e c o n t e n t s ;

    4 . i t s s i z e ;

    5 . t i m e s o f c r e a t i o n and l a s t m o d i f i c a t i o n ;

  • 8/17/2019 UnixEditionZero OCR

    12/53

    - 12 -

    6 . t h e number o f l i n k s t o t h e f i l e ; t h a t i s , t h e number o f

    t ime s t a p p e a r s i n a d i r e c t o r y ;

    7 . b i t s i n d i c a t i n g whether t h e f i l e i s a d i r e c t o r y and whether

    t i s s p e c i a l ( i n which c a s e t h e s i z e and d i s k addresses -

    a r e m e a n i n g l e s s ;

    . a b i t i n d i c a t i n g whether t h e f i l e i s l a r g e o r sm a l l .

    There i s space i n each i - n o d e f o r e i g h t d i s k a d d r e s s e s . A f i l e

    ) which f i t s i n t o e i g h t o r f ewer 64-word 1 2 8 - b y t e b l o c k s i s c o n -

    s i d e r e d s ma l l ; i n t h i s ca s e t h e a d d r e s s e s o f t h e b l o c k s t h e m -

    s e l v e s a r e s t o r e d . For l a r g e f i l e s , each o f t h e e i g h t d i s k ad -

    d r e s s e s may p o i n t t o an i n d i r e c t b l o c k o f 64 words c o n t a i n i n g t h e

    a d d r e s s e s o f t h e blocks c o n s t i t u t i n g t h e f i l e i t s e l f . Thus f i l e s

    may be as l a r g e a s 8•64•128 , o r 65 ,536 b y t e s .

    When t h e number o f l i n k s t o a f i l e d r o p s t o z e r o , i t s c o n t e n t s

    a r e f r e e d and i t s i - n o d e i s marked unused .

    To t h e u s e r , b o t h r e ad ing and w r i t i n g o f f i l e s appears t o be s y n -

    chronous and u n b u ff e r e d . ~ a t i s , i m m e d i a t e l y a f t e r r e t u r n frohl a

    r e a d c a l l t h e d a t a i s a v a i l a b l e , and c o n v e r s e l y a f t e r a w r i t e t h e

    u s e r s workspace may be r e u s e d . In f a c t t h e sys tem m a i n t a i n s , u n -

    s e e n by t h e u s e r , a r a t h e r c o m p l i c a t e d b u f f e r i n g mechanismo

    Suppose a w r i t e c a l l i s made s p e c i f y i n g t r a n s m i s s i o n o f a s i n g l e

    b y t e . UNIX w i l l s ea r ch i t s own b u f f e r s t o s e e whether t h e a f f e c -

    t e d d i s k b l o c k c u r r e n t l y r e s i d e s i n i t s own b u f f e r s ; i f n o t , t

    w i l l be r e a d i n from t h e d i s k . Then t h e a f f e c t e d by t e i s r e p l a c e d

    i n t h e b u f f e r and an e n t r y i s mad e i n a l s t o f b l o c k s t o c e

    w r i t t e n on t h e d i s k . The r e t u r n f rom t h e w r i t e c a l l may t h e n t a k e

    p l a c e , a l t h o u g h t h e a c t u a l I / O may n o t be complet e d u n t i l a l a t e r

  • 8/17/2019 UnixEditionZero OCR

    13/53

    , - 13 -

    t imeo C o n v e r s e l y, i f a s i n g l e by t e i s r e ad , t h e s y s t e ~d e t e r m i n e s

    whether t h e d i s k b l o c k i n which t h e b y t e i s l o c a t e d i s a l r e a d y i n

    one o f t h e s y s t e m s b u f f e r s ; i f s o , t h e by t e can be r e t u r n e d

    immedia te ly. I f n o t t h e b l o c k i s r e a d i n t o a b u f f e r and t h e byte ·

    p i c k e d o u t . Because s e q u e n t i a l r e a d in g o f a f i l e i s so COITuuon

    UNIX a t t e m n t s t o o p t i m i z e t h i s s i t u a t i o n by p r e r e a d i n g t h e d i s k

    b l o c k f o l l o w i n g t h e one i n which t h e r e q u e s t e d by t e i s found .

    Th i s s t r a t e g y t e n d s t o minimize and i n some ca se s e l i m i n a t e d i s k

    l a t e n c y d e l a y s .

    A program which r e a d s o r w r i t e s f i l e s i n u n i t s o f 128 b y t e s has

    an advan tage o v e r a program which r e a d s o r w r i t e s a s i n g l e b y t e

    a t a t i m e , b u t t h e g a i n i s n o t immense. As an example , t h e e d i t o r

    ed ( 8 . 9 and A2.4 below) was o r i g i n a l l y w r i t t e n f o r s i m p l i c i t y

    t o do I /O one c h a r a c t e r a t a t i m e ; t i n c r e a s e d i t s speed by a

    f a c t o r o f about two when t was r e w r i t t e n t o u s e 1 2 8 - b y t e u n i t s .

    Because t h e sys tem a t t e m p t s t o r e t a i n c o p i e s o f t h e most r e c e n t l y

    used d i s k b l o c k s i n c o r e t h e speed ga i n i n d e a l i n g w i t h l a r g e

    u n i t s comes p r i n c i p a l l y f rom e l i m i n a t i o n o f sys tem overhead , n o t

    from l a t e n c y d e l a y s .

    ~ The S h e l l

    ~ · Genera l

    Communication w i t h UNIX i s c a r r i e d on w i t h t h e a i d o f a program

    c a l l e d t h e S h e l l . The S h e l l i s a command l i n e i n t e r p r e t e r : t

    r e a d s l i n e s t y p e d by t h e u s e r and i n t e r p r e t s them as r e q u e s t s t o

    e x e c u t e o t h e r programs . In s i m p l e s t form, a command l i n e c o n s i s t s

    o f t h e command name f o l l o w e d by a rgument s t o t h e command, a l l

  • 8/17/2019 UnixEditionZero OCR

    14/53

    )

    - 14 -

    s e p a r a t e d by space s :

    The She l l s p l i t s up t h e command name and t h e arguments in to ·

    s e p a r a t e s t r i n g s . Then a f i l e wi th name command i s sought ;

    command may be a pa th name i nc lud ing t h e / c h a r a c t e r t o s p e c i f y

    any f i l e i n t he sys tem. I f command i s found t i s brought i n t o

    co re and executed . The arguments c o l l e c t e d by t he She l l a re a c -

    c e s s i b l e t o t h e command. When t h e command i s f i n i s h e d , t h e She l l

    resumes i t s own execu t ion and i n d i c a t e s i t s r e a d i n e s s t o accep t

    ano the r command by t yp ing t h e prompt c h a r a c t e r •

    I f f i l e command cannot be found t h e S h e l l p r e f i x e s t h e s t r i n g

    / /i n t o command and a t t e m p t s aga in t o f i n d t h e f i l e . Direc to ry

    11 / b i n con ta in s a l l t h e commands p rov ided by t h e sys tem i t s e l f .

    5 .2 Standard l / Q

    The d i s c u s s i o ~o f I /O g iven above seems t o imply t h a t eve ry f i l e

    used by a program must be opened o r c r e a t e d by t h e program i n

    o r d e r t o ge t a f i l e d e s c r i p t o r f o r t h e f i l e . In f a c t , t h i s i s n o t

    _ q u i t e t r u e . There a r e two f i l e s a lways a c c e s s i b l e t o eve ry

    program wi thou t an e x p l i c i t open o r c r e a t e ; t hey have f i l e

    d e s c r i p t o r s 0 and 1 . As a program be g in s e x e c u t i o n f i l e 1 i s

    open f o r w r i t i n g , and i s b e s t unders tood as t h e s t anda rd ou tpu t

    _ f i l e . Except under c i rcumstances i n d i c a t e d be low t h i s f i l e i s

    t h e u s e r 6 s t y p e w r i t e r. Thus programs which wish t o w r i t e i n f o r ma -

    t i v e o r d i a g n o s t i c i ~ f o r m t i o no r d i n a r i l y u s e f i l e d e s c r i p t o r G

    Converse ly f i l e 0 s t a r t s o f f open f o r r ead ing and programs

  • 8/17/2019 UnixEditionZero OCR

    15/53

    - 15 -

    which wish t o r e a d messages t y p e d b y t h e u s e r u s u a l l y r e a d t h i s

    f i l e .

    The S h e l l i s a b l e t o change t h a s t anda rd ass ignments o f t h e s e

    f i l e d e s c r i p t o r s from t h e u s e r ' s t y p e w r i t e r p r i n t e r and keyboard .

    P r e f i x e d by > ,f one o f t h e arguments t o a command i s f i l e

    d e s c r i p t o r 1 w i l l , f o r t h e d u r a t i o n o f t h e command r e f e r t o t h e

    f i l e named a f t e r t h e > . For example

    l s

    o r d i n a r i l y l i s t s , on t h e t y p e w r i t e r , t h e names o f t h e f i l e s i n

    t h e c u r r e n t d i r e c t o r y . The command

    l s ) f i l e s

    c r e a t e s .f i l e c a l l e d f i l e s and p l a c e s t h e l i s t i n g t h e r e . Thus> . 'h e argument f i l e s means p l a c e o u t p u t on

    o t h e r hand

    ed

    11 f l .. ,i e s . On t h e

    o r d i n a r i l y e n t e r s t h e e d i t o r , which t a k e s r e qu e s t s from t h e u s e r

    v i a h i s t y p e w r i t e r . The command

    ed ( s c r i p t

    i n t e r p r e t s s c r i p t ' ' a s a f i l e o f e d i t o r comman d s ; t h u s < s c r i p t

    means ' t a k e i n p u t f rom ,s c r i p t .

    iU t h o u gh t h e f i l e na me f o l l o w i n g < o r > a pp ea r s t o be a n a r -

    gument t o t h e command i n f a c t i t i s i n t e r p r e t e d comple te ly by

    t h e Sh e l l and i s not p a s s e d t o t h e com mand a t a l l . Thus no s p e -

  • 8/17/2019 UnixEditionZero OCR

    16/53

    - 16 -

    c i a l c o d i n g i s needed w i t h i n each command; t h e command need

    mere ly use t h e s t anda rd f i l e d e s c r i p t o r s O and 1 where

    a p p r o p r i a t e .

    ~ · l Command Sepa ra to r s

    Another f e a t u r e p r o v i d e d by t h e S h e l l i s r e l a t i v e l y

    s t r a i g h t f o r w a r d . Commands need n o t be on d i f f e r e n t l i n e s ; i n s t e a d

    t h e y may be s e p a r a t e d by semico lons .

    l s ; ed

    w i l l f i r s t l i s t t h e c o n t e n t s o f t h e c u r r e n t d i r e c t o r y , t h e n e n t e r

    t h e e d i t o r .

    A r e l a t e d f e a t u r e i s more i n t e r e s t i n g . I f a command i s fo l lowed

    .. .. hby ; t e S h e l l w i l l no t wa i t f o r t h e command t o f i n i s h b e f o r e

    r e t u r n i n g w i t h . .i t s s i g n a l @ ; i n s t e a d , i t i s r e a d y immedia te ly

    t o a c c e p t a new c o m m n d ~For example ,

    .as source o u t p u t

    c a u s e s s o u r c e t o be assembled , w i t h d i a g n o s t i c o u t p u t going t o

    ) u t p u t ; however, no m a t t e r how l o n g t h e assembly t a k e s , t h eS h e l l r e t u r n s immedia te ly. The may be u s e d s e v e r a l t imes i n a

    l i n e :

    ). /

    a s s o u r c e o u t p u t l s f i l e s

    does b o t h t h e assembly and t h e l i s t i n g i n t h e background. In a l l

    h e examples above us ing , an ou tpu t f i l e o t h e r t h a n t h e

    t y p e w r i t e r was prov ided ; i f t h i s had no t been done, t h e c u t o u t s

  • 8/17/2019 UnixEditionZero OCR

    17/53

    )

    - 17 -

    o f t h e v a r i o u s commands would have b e e n in te rming led . ,

    I n c i d e n t a l l y , i n t h e exar.t-p a c e s b e f o r e and a f t e r t h eh e

    p l e s above a r e n o t n e c e s s a r y. )

    ~ o The S h e l l a s a Command

    The S h e l l i s i t s e l f a command, and may be c a l l e d r e c u r s i ve lyo

    Suppose f i l e r y o u t c o n t a i n s t h e l i n e s

    a s s o u r c ev a . o u t t e s t p r o g

    t e s t p r o g

    The lY command c a u s e s t h e f i l e a . o u t t o b e renamed t e s t p r o g .H H

    a . o u t i s t h e b ina ry ) o u t p u t o f t h e a s s e m b l e r, · r e a d y t o b e

    execu tedo Thus i t h e t h r e e l i n e s above were t y p e d on t h e c o n -

    o l e , s o u r c e would be assembled , t h e r e s u l t i n g program named

    e s t p r o g , andH H

    t e s t p r o g e x e c u t e d . When t h e l i n e s a r e i nV H

    t r y o u t , t h e command

    sh t r v o u t

    would c a u s e t h e S h e l l . sh t o e x e c u t e t h e commands s e q u e n t i a l l y .

    The S h e l l h a s f u r t h e r c a p a b i l i t i e s , i n c l u d i n g t h e a b i l i t y t o i n -

    t e r p r e t p a r a m e t e r s t o f i l e d cormnand sequences ; see s e c t i o n 8 . 1 8 . )

    When t h e u s e r t y p e s t h e & c h a r a c t e r a s p a r t o f a command l i n e ,

    he i s e x p l i c i t l y i nvok inq t h e m u l t i t a s k i n g f a c i l i t i e s o f mnx.Tha t i s , he i s c r e a t i n g a p r o c ~ which r u n s a s y n c h r o n o u s l y :::rcn

    h i s normal command s t r e a :n. lU t h o u sr"ri t h i s a b i l i t y i s q u i t e c o n -

    v e n i e n t f o r t h e u s e r d i r e c t l y , i t i s e v en o r e u se f u l t o ~ ; I X

    i t s e l f .

  • 8/17/2019 UnixEditionZero OCR

    18/53

    - 18 -

    2·2 P r o c e s s e s and f o r k i n q

    A o r o c e s s i n UNIX i s t h e e x e c u t i o n o f a program. The e v i d e n c e o f

    t h e e x i s t e n c e o f a p r o c e s s i s a imaae . While t h e p r o c e s so r

    i s e x ec u t i n g on b e h a l f o f a p r o c e s s , t h e c o r e image q u i t e

    n a t u r a l l y , r e s i d e s i n t h e c o r e memory o f t h e compute r ; d u r i n g t h e

    exec u t i o n o f o t h e r p r o c e s s e s , a c o r e image i s k e p t on t h e d i s k .

    In o r d e r t o p r o v i d e f a s t r e s p o n s e t o u s e r s r e q u e s t s , UNIX, l i k e

    most t i m e - s h a r i n g s y s t e m s swaps t h e c o r e images o f p r o c e s s e s

    be tween c o r e and t h e d i s k .

    Excep t w h i l e UNIX i s b o o t s t r a p p i n g i t s e l f i n t o o p e r a t i o n , a new

    p r o c e s s can come i n t o e x i s t e n c e i n o n l y one way: by u s e o f t h e

    f o r k sys tem c a l l .

    p r o c e s s i d = f o r k ( l a b e l )

    When fork. i s e x e c u t e d by a p r o c e s s , t s p l i t s i n t o two i n d e p e n -

    d e n t l y e x e c u t i n g p r o c e s s e s . The two p r o c e s s e s have · co re imageswhich a r e o p i ~ so f e a c h o t h e r , b u t t h e y a r e n o t p r e c i s e l y

    e q u i v a l e n t : one o f them i s c o n s i d e r e d t h e p a r e n t p r o c e s s . I n t h e

    p a r e n t , c o n t r o l does n o t r e t u r n d i r e c t l y from t h e f o r k , b u t i n -

    ) s t e a d p a s s e s t o l o c a t i o n l a b e l ; i n t h e c h i l d p r o c e s s , t h e r e i s a

    normal r e t u r n . The p r o c e s s i d r e t u r n e d by t h e f o r k c a l l i s t h e

    i d e n t i f i c a t i o n o f t h e o t h e r , o ff s p r i n r y p r o c e s s .

    Because t h e r e t u r n p o i n t s i n t h e p a r e n t and c h i l c r o c e s s a r e 1'.J':.

    t h e sa m e , each copy o f a p ro g r a ; l e x i s t i n g a f t e r a for} c may d e t e r -

    min e wh e t h e r t i s t h e p a r e n t o r c h i l d p r o c e s s .

    2.6 ~ x u t i o no f Droqr am s

  • 8/17/2019 UnixEditionZero OCR

    19/53

    \I

    - 19 -

    Anothe r sys t em p r i m i t i v e on which t h e S h e l l depends h e a v i l y i s

    i nvoked by

    s t a t u s = e x e c u t e ( f i l e , r ~ a r g 2 , • • • , a r g n

    which r e q u e s t s t h e s y s t e m t o r e a d i n and e x e c u t e t h e progra :n

    named b y f i l e , p a s s i n g i t a rgument s a r a 1 , M.g2, • • • a r - : •n

    O r d i n a r i l y , a r a 1 s h o u l d b e t h e same s t r i n g a s f i l e . I f t h i s c a l l

    i s s u c c e s s f u l , c o n t r o l n e v e r r e t u r n s t o t h e program which u s e s

    i t T h a t i s , t h e image o f t h e named f i l e r e p l a c e s t h e c u r r e n t

    program. Only i f t h e c a l l f a i l s , f o r example b e c a u s e f i l e c o u l d

    n o t e found o r because i t s e x e c u t e - p e r m i s s i o n b i t was n o t s e t ,

    d o e s a r e t u r n t a k e p l a c e f rom t h e e x e c u t e p r i m i t i v e .

    The t h i r d and l a s t p r o c e s s c o n t r o l sys tem c a l l used by t h e S h e l l

    i s

    p r o c e s s i d , s t a t u s = w a i t ( )

    This p r i m i t i v e c a u s e s i t s c a l l e r t o suspend e x e c u t i o n u n t i l one

    o f i t s c h i l d r e n has c o m p l e t e d e x e c u t i o n . Then w a i t · r e t u r n s t h e

    p r o c e s s i d o f t h e t e r m i n a t e d p r o c e s s and a s t a t u s v a l u e i n d i c a t i n g

    _how t h e p r o c e s s d i e d . ( P r o c e s s e s which a r e n e v e r w a i t e d f o r d i e

    u n n o t i c e d and presumably unmourned.

    ~ · O n e r a t i o n o f t h e S h e l l

    The o u t l i n e o f t h e o p e r a t i o n o f t h e S h e l l can now be u n d e r s t o o d .

    Most o f t h e t h e t i m e , t h e Sh e l l i s w a i t i n g f o r t h e u s e r t o t ype a

    command. ~ f u e nt h e new l i n e c h a r a c t e r i s t y p e d , t h e S h e l l s r e ad

    c a l l r e t u r n s . The S h e l l a n a l y z e s t h e command l i n e , p u t t i n g tr1e

  • 8/17/2019 UnixEditionZero OCR

    20/53

    - 20 -

    a rguments i n a form a p p r o p r i a t e f o r e xecu t e . Then f o r k i s c a l l e d o

    The c h i l d p r o c e s s whose code o f c o u r s e i s s t l l t h a t o f t h e

    S h e l l t h e n a t t e m p t s t o per fo rm an e x e c u t e w i t h t h e a p p r o p r i a t e

    ) arguments . I f s u c c e s s f u l t h i s w i l l b r i n g i n and s t a r t execu t io r r

    o f t h e program whose name was g i v e n . Meanwhi le , t h e o t h e r p r o c e s s

    r e s u l t i n g from t h e f o r k which i s t h e p a r e n t p r o c e s s w a i t s f o r

    t h e c h i l d p r o c e s s t o d i e . When t h i s happens , t h e S h e l l knows t h e

    command i s f i n i s h e d so t t y p e s o u t....

    @ and r e a ds t h e t y p e w r i t e r

    t o o b t a i n ano the r command.

    Given t h i s frameworJ(, t h e i m p l e m e n t a t i o n o f background p ro c e s se s

    i s t r i v i a l ; whenever a command l i n e t e r m i n a t e s w i t h .... , t h eS h e l l mere ly r e f r a i n s f rom w a i t i n g f o r t h e p r o c e s s which t

    c r e a t e d t o e x e c u t e t h e command.

    H a p p i l y, a l l o f t h i s mechanism meshes v e r y n i c e l y w i t h t h e n o t i o n

    o f s t a n d a r d i n p u t and o u t p u t f i l e s . When a p r o c e s s i s c r e a t e d by

    t h e f o r k p r i m i t i v et

    i n h e r i t s no t on l y t h e c o r e fmage o ft s

    p a r e n t b u t a l s o a l l t h e f i l e s c u r r e n t l y open i n i t s p a r e n t i n -

    e l u d i n g t h o s e w i t h f i l e d e s c r i p t o r s 0 and 1 . The S h e l l o f

    c o u r s e u s e s t h e s e f i l e s t o r e a d command l i n e s and t o w r i t e i t s

    1 @ ,s i g n a n ~ i n t h e o r d i n a r y c a s e i t s c h i l d r e n - - t h e command

    r i s g i v e n however, t h e o f f s p r i n g p r o c e s s j u s t b e f o re t

    p e r f o r m s e xecu t e , c l o s e s f i l e 0 o r 1 r e s p e c t i v e l y and opens t h e

    na m e d f i l e . Because t h e p r o c e s s i n which t h e command program r u n s

    sir:i p l y t e r m i n a t e s wh e n t i s t h r o u g h , t h e a s s o c i a t i o n between a

    f i l e s p e c i f i e d a f t e r < o r > and f i l e d e s c r i p t o r O o r 1 i s e n -

    ded a u t o m a t i c a l l y when t h e p r o c e s s d i e s . T h e r e f o r e t h e S h e l l need

  • 8/17/2019 UnixEditionZero OCR

    21/53

    - 21 -

    no t know t h e a c t u a l names o f t h e f i l e s which a r e i t s own s t a n da rd

    i n p u t and o u t p u t , s ince t need n e v e r r eopen them.

    In o r d i n a r y c i r c u m s t a n c e s , t h e main l o o p o f t he S h e l l never

    t e r m i n a t e s . The main loop i nc ludes t h a t b r a n c h o f t h e r e t u r nfrom f o r k b e l o n g i n g t o t h e p a r e n t proces s ; t h a t i s , t he branch

    which does a w a i t , t h e n r e a ds ano the r command l i n e . The one

    t h i n g which causes t he S h e l l t o t e r m i n a t e i s d i s c o v e r i n g an e n d -

    o f - f i l e c o n d i t i o n on i t s i n p u t f i l e . Thus, when t h e S h e l l i s ex -

    ec u t ed a s a command w i t h a g i v e n i n p u t f i l e , as i n

    sh comf i l e

    t h e commands i n omf i l e w i l l b e e x e c u t e d u n t i l t h e end o f

    l t c o m f i l e i s reached ; t h e n t h e i n s t a n c e o f t h e She l l i nvoked by

    sh w i l l t e r m i n a t e . Since t h i s S h e l l p r o ces s i s t h e c h i l d o f

    ano the r i n s t a n c e o f t h e S h e l l , t h e w a i t e x e c u t e d i n t he l a t t e r

    w i l l r e t u r n , and a n o t h e r command may be p r oces sed .

    The i n s t a n c e s 9 f t he S h e l l t o which each UNIX u s e r t y p e s com... Tlands

    a r e t h e m s e l v e s c h i l d r e n o f ano the r p r o c e s s . The l a s t s t e p i n t he

    i n i t i a l i z a t i o n o f UNIX i s t h e c r e a t i o n o f a s i n g l e p r oce s s and

    1 t h e i nv oc a t i on v i a exe c u t e ) o f a program c a l l e d i n i t . The code/

    f o r i n i t i s k e p t i n a f i l e , l i k e e v e r y o t h e r command. I t s r o l e i s

    t o c r e a t e one p r o c e s s f o r each t y p e w r i t e r channe l which may be

    d i a l e d up by a u s e r . The v a r i o u s s u b i n s t a n c e s o f i n i t open t he

    a p p r o p r i a t e t y p e w r i t e r s f o r i n p u t and o u t p u t . Since when i n i t was

    i nvoked t h e r e were no f i l e s open , i n each p roces s t h e t y p e w r i t e r

    keyboard w i l l r e c e i v e f i l e d e s c r i p t o r O and t h e p r i n t e r f i l e

    d e s c r i p t o r 1 . Each p roces s t y pes o u t a message r e q u e s t i n g t h a t

  • 8/17/2019 UnixEditionZero OCR

    22/53

    22

    t h e u s e r l o g i n and w a i t s , r e a d i n g t h e t y p e w r i t e r , f o r a r e p l y o

    At t h e o u t s e t , no one i s l o g g e d i n , so e a c h p r o c e s s s imply hangso

    F i n a l l y someone t y p e s h i s name o r o t h e r i d e n t i f i c a t i o n . The a p -

    p r o p r i a t e i n s t a n c e o f i n i t wakes u p r e c e i v e s t h e l o g - i n l i n e , ·

    and r e a d s a password f i l e . I f t h e u s e r i s f o u n d and i h e i s

    a b l e t o s u p p l y t h e c o r r e c t p a s s w o r d i n i t changes t o t h e u s e r s

    d e f a u l t c u r r e n t d i r e c t o r y , s e t s t h e u s e r number t o t h a t o f t h e

    p e r s o n l o g g i n g i n , and p e r f o r m s an e x e c u t e o f t h e S h e l l . At t h i s

    p o i n t t h e S h e l l i s r e a d y t o r e c e i v e commands and t h e l o g g i n g - i n

    p r o t o c o l i s c o n p l e t e .

    Meanwhi le t h e mains t r eam p a t h o f i n i t ( t h e p a r e n t o f a l l t h e

    s u b i n s t a n c e s o f i t s e l f which w i l l l a t e r become S h e l l s ) d o e s a

    w a i t . I f one o f t h e c h i l d p r o c e s s e s t e r m i n a t e s , e i t h e r b e c a u s e a

    S h e l l found an end o f f i l e o r b e c a u s e a u s e r t y p e d an i n c o r r e c t

    name o r p a s s w o r d t h i s p a t h o f i n i t s i m p l y r e c r e a t e s t h e d e f u n c t

    p r o c e s s , which r eopens t h e a p p r o p r i a t e i n p u t and o u t p u t f i l e s and

    t y p e s a n o t h e r l o g - i n message . Thus a u s e r may l o g o u t s i m p l y b y

    t y p i n g t h e e n d - o f - f i l e s e q ~ e n ei n p l a c e o f a command t o t h e

    S h e l l o

    60 Census o f S o e c i a l F i l e s

    Here i s a l i s t o f t h e s p e c i a l f i l e s c u r r e n t l y imp lemen ted . S i n c e

    an e n t r y f o r e a c h r e s i d e s i n t h e r o o t d i r e c t o r y , t h e f i l e nxyz

    /may b e r e f e r r e d t o by xyz • A l t e r n a t i v e l y , one may l i n k t o a ny

    o f t h e s e i l e s under any name d e s i r e d .

  • 8/17/2019 UnixEditionZero OCR

    23/53

    - 23 -

    hen r e a d , p p t r e f e r s t o t h e p a p e r t a p e r e a d e r ; when w r i t t e n 9

    t o t h e punch . Nul l c h a r a c t e r s a r e i g n o r e d f o r b o t h r e a d i n g and

    w r i t i n g , so p t i s s u i t a b l e o n l y f o r ASCII n o t b i n a r y )

    i n f o r m a t i o n ; on t h e o t h e r hand t h e program need n o t t a k e a c c o u n t

    o f t h e l e a d e r o r t r a i l e r . End o f f i l e o c c u r s d u r i n g a r e a d when

    t h e end o f t h e t a p e p a s s e s t h r o u g h t h e s e n s o r s .

    p p t a l s o r e f e r s t o p a p e r t a p e . The t a p e i s · i n a b l o c k e d f o r w a t

    w i t h checksums. Comple te ly a r b i t r a r y i n f o r m a t i o n may be w r i t t e n

    and r e c o v e r e d unchanged i n t h i s mode.

    r o n t-

    This i s raw i n p u t and o u t p u t f o r p a p e r t a p e . Every c h a r a c t e r i s

    p a s s e d t o t h e program i n c l u d i n g n u l l s , so t h a t t h e p r o g r a ~must

    know when t h e l e a d e r ends and i n f o r m a t i o n b e g i n s d u r i n g a r e a d .

    On t h e o t h e r h ~ n d t h i s mode i s s u i t a b l e when t a p e s o f u n u s u a l

    f o r m a t mu s t be r e a d .

    This i s t h e c o n s o l e t y p e w r i t e r . N u l l c h a r a c t e r s a r e i g n o r e d f o r

    b o t h r e a d i n g and w r i t i n g . For r e a d i n g t h e l i n e i s a u n i t o f

    i n f o r m a t i o n ; p rogram r e a d i n g t t y w i l l w a i t u n t i l a whole l i ne

    h a s b e en t y p e d a nd a t most one l i n e w i l l be p a s s e d b a ck t o t he

    p r o g r a m. Ho we v e r , ch a r a c t e r s may b e r e a d on e a t a m fro:n t he

    l i n e e

  • 8/17/2019 UnixEditionZero OCR

    24/53

    - 4 -

    ,,on i n p u t , e r a s e and k i l l p r o c e s s i n g a r e per fo rmed: w i l l e r a s e

    h e l a s t c h a r a c t e r t yped ; @ k i l l s t h e e n t i r e l i n e .

    The ASCII c h a r a c t e r OT s i g n a l s an end o f f i l e t o t h e programo

    The ASCII new l i n e c h a r a c t e r i s t h e s t a n d a r d means o f end ing ani n p u t l i n e . On t h e Te l e t y p e models 33 and 35 and some o t h e r t e r -

    mina ls UNIX n u s t s i m u l a t e t h i s f u n c t i o n by echoing a e t u r n

    c h a r a c t e r when t r e c e i v e s a l i n e space (whose code cor responds

    ) t o t h e ASCII new l i n e . )

    )

    The name t y r e f e r s t o t h e u s e r ' s own t y p e w r i t e r , no m a t t e r

    which p h y s i c a l channe l he may be u s i n g . There a r e a l s o s p e c i a l

    (i l e s f o r each t y p e w r i t e r :J They have t h e names c t t y f o r t h e

    c e n t r a l s i t e t e r m i n a l ) ,

    u s e r ' s t y p e w r i t e r s ) .

    and t t y 1 ' t t y 2 ' • • • t y n ( f o r

    ..his i s raw t y p e w r i t e r I o. I t i s i d e n t i c a l t o t t y f o r o u t -

    p u t , b u t on i n p u t t h e p r o g ~ mw a i t s o n l y u n t i l a t · l e a s t one

    c h a r a c t e r has been t y p e d b e f o r e a r e t u r n from t h e r e a d occ u r s . No

    e r a s e o r k i l l p r o c e s s i n g i s done.

    These f i l e s r e f e r t o DECT PE l o g i c a l u n i t s 0 and 1 . When t h e y a r e

    opened , t h e program w a i t s u n t i l a t a p e i s mounted on t h e ap -

    p r o p r i a t e d r i v e .

  • 8/17/2019 UnixEditionZero OCR

    25/53

    - 25 -

    T h i s f i l e r e f e r s t o t h e e n t i r e d i s k i n a way i n d e p e n d e n t o f t h e

    f i l e s y s t e m ; i t r e a d s o r w r i t e s t h e p h y s i c a l b l o c k c o r r e s p o n d i n s

    t o t h e c u r r e n t f i l e p o i n t e r .

    J One u s e o f t h i s f i l e d e m o n s t r a t e s c o n v i n c i n g l y t h e v e r s a t i l i t y of·t h e s p e c i a l f i l e c o n c e p t . T h e r e i s a program c a l l e d check which

    s c r u t i n i z e s t h e e n t i r e f i l e s y s t e m t o d e t e r m i n e i t s c o n s i s t e n c y

    and t h e number o f d i s k b l o c k s u s e d f o r v a r i o u s p u r p o s e s . T h i s

    ) program i s i n no s e n s e p a r t o f t h e sys tem; i t i s a n o r d i n a r y COT.-/

    mand i nvo icab le by any u s e r . Check o o e r a t e s by r e a d i n g t h e f i l e

    a· . S k e I n t h i s way i t i s a b l e t o examine t h e l i s t o f i - n o c e s

    cf . , s e c t i o n 4) which d e f i n e f i l e s w i t h o u t d e p e n d i n g on ad hoc

    s y s t e m c a l l s t o o b t a i n i t s i n f o r m a t i o n •

    §• § syste:-'.'I

    T h i s s p e c i a l f i l e c a u s e s t h e a r e a o f c o r e memory o c c u p i e d by t h e

    s y s t e m t o be t r e a t e d a s a f i l e . Thus t h e s y s t e m c a n ~ e examined

    and p a t c h e d d u r i n g o p e r a t i o n y u s e o f t h e o r d i n a r y d e b u g g e r ~

    d i s c u s s e d b e l o w.

    The PDP-11 h a r d w a r e d e t e c t s a number o f program f a u l t s such a s

    r e f e r e n c e s t o n o n - e x i s t e n t memory, un implemen t ed i n s t r u c t i o n s

    and odd a d d r e s s e s u s e d where an e v e n a d d r e s s i s r e q u i r e d . Such

    f a u l t s c a u s e t h e p r o c e s s o r t o t r a p t o a s y s t e m r o u t i n e . When a n

    i l l e g a l a c t i o n i s c a u g h t t h e s y s t e m w r i t e s t h e u s e r s c o r e i maq e

    on f i l e c o r e i n t h e c u r r e n t , w o r k i n g d i r e c t o r y . B e c a u s e o f t h e

    w y t h e h r d w re nd t h e s y s t e m o p e r a t e t h e c o n t e n t s o f a l l t h e

  • 8/17/2019 UnixEditionZero OCR

    26/53

    - 6 -

    p rog ra m-ac c es s ib l e r e g i s t e r s a r e s t o r e d w i t h i n t h i s c o r e i r age

    f i l e . Thus , t h e debugger db d i s c u s s e d below can be u s e d t o d e t e r -

    mine t h e s t a t e o f t h e progrrun a t t h e t i m e o f t h e f a u l t .

    ' \

    J The u s e r may a l s o f o r c e t h e program t o s t o p and a c o r e image f i l e

    t o be w r i t t e n by send ing an i n t e r r u p t s i g n a l . C u r r e n t l y t h i s s i g -

    .. \n a l i s g e n e r a t e d by t y p i n g t h e ASCII FS c h a r a c t e r ( c o n t r o l

    on model 37 Te l e t y p e s ) . Thus programs which a r e l o o p i n g o r a b o u t

    ) which t h e u s e r h a s second t h o u g h t s inay b e h a l t e d .

    I f t h e u s e r h a s s e v e r a l p r o c e s s e s i n e x e c u t i o n s i m u l t a n e o u s l y

    ( b e c a u s e he used t h e & f a c i l i t y o f t h e S h e l l ) o n l y one o f t h e s e

    p r o c e s s e s i s stoppeCl, and t h e r e i s no c o n t r o l o v e r which one ; t

    depends on which i s c u r r e n t l y i n ex e c u t i on o r e x e c u t e s next. ,

    C l e a r l y t h i s s i t u a t i o n l e a v e s much t o be d e s i r e d , f o r s e v e r a l

    r e a s o n s :

    1., when t h e u s e r h a s s e v e r a l p r o c e s s e s h e c a n n o t i n t e r r u p t

    w i t h any s e l e c t i v i t y ;

    2., i n a l l ~ s e st h e r a t h e r l a r g e c o r e image f i l e ~ s produce d ,

    when t h e u s e r ma y m e r e l y have wished , f o r ex a mp l e , t o s t o p

    a l o n g p r i n t o u t ;

    3 . t i s o f t e n u s e f u l t o send an asynchronous s i g n a l t o a \r o c e s s w i t h o u t s t o pp i n g t ( f o r example by c a u s i n g a t r a p

    t o an a g r e e d - u p on l o c a t i o n w i t h i n t h e p r o c e s s s c o r eimage . )

    Dou b t l e s s , t h8 r e f o r e , t h e i n t e r r up t :: a c i l i t y w l l be r e wo r ec1 i n

    t h e f u t u r e o Unf o r t u n a t e l y , t h e r e a r e n o t o n l y i mpl e me n t a t i o n

    p r o b l e ms bu t e v e n c o nc e p t u a l on e s - - c . J . how does on e spec i : : y c.

  • 8/17/2019 UnixEditionZero OCR

    27/53

    27

    p r o c e s s which may have s t a . r t e d an a r b i t r a r y t i m e ago?

    g. Commands

    T h i s s e c t i o n summarizes s e v e r a l o f t h e commands a v a i l a b l e i n

    UNIX. The l i s t i s no t e x h a u s t i v e b u t i t c o v e r s t h o s e most f r e -

    q u e n t l y u s e d . The a s s e m b l e r ~ t h e debugger d b t h e e d i t o r

    and DECTAPS m a n i p u l a t o r t a o a r e documented i n more d e t a i l i n

    Appendix 2 .

    Where an a rgumen t lii

  • 8/17/2019 UnixEditionZero OCR

    28/53

  • 8/17/2019 UnixEditionZero OCR

    29/53

    - 9 -

    i n t e r e s t i n g . Reca l l t h a t e a c h o r d i n a r y c o m ~ a n di s execu ted as a

    s e p a r a t e p roces s c r e a t e d by t h e S h e l l . I f t h e s y s t em s c h d i r

    p r i m i t i v e were execu ted i n such a p r o c e s s i t would have e s s e n -

    - t i a l l y no e f f e c t s i n c e t h e p r o c e s s would t e rmina t e i n s t a n t l y

    w i thou t a f f e c t i n g t h e c u r r e n t d i r e c t o r y o f t h e S h e l l p r oce s s and

    i t s s u b s e q u e n t o f f s p r i n g . T h ~ ShAll i t s e l f r e c ogn i ze s t h e c ~ d i r

    command and c a l l s t he sys tem t o change d i r e c t o r i e s w i thou t

    c r e a t i n g a new p roces s .

    s ~ chmod chancre mode o f f i l e

    To change t h e p r o t e c t i o n b i t s f o r a s e t o f f i l e s

    chmod mode name 1 namen

    The modes o f 1 , ~ a r e s e t t o mode. Mooe i s an o c t a l

    number whose b i t s i n t h e b i n a r y r e p r e s e n t a t i o n have t he fo l l r n i n g

    meanings:

    1 w r i t e non-owner2 r e a d non-owner4 w r i t e · owner

    1 0 r e a d owner20 e x e c u t e40 s e t u s e r ID on e xecu t i on

    See a l s o s e c t i o n 3 .4 on t h e p r o t e c t i o n sys tem. Most command

    programs c r e a t e f i l e s w i t h mode 1 7 ; t h e a s s e m b l e r s a . o u t f i l e

    has mode 37.

    Q ~ chown ~ ~ a e own e r o f f i l e s

    To chang e t h e own e r o f a se qu e nc e o f f i l e s

    chown owner name 1 namen

  • 8/17/2019 UnixEditionZero OCR

    30/53

    - 30 -

    owner i s a u s e r number a s s i g n e d by t h e s y s t e m a d m i n i s t r a t o r s c

    Only t h e owner o f a f i l e may d o n a t e t h e f i l e t o a n o t h e r u s e r o

    N o t i c e t h a t chown does n o t change t h e d i r e c t o r y i n which t h e l i n k

    t o t h e f i l e e x i s t s .

    To make a copy o f a f i l e ,

    8 . Q d b debuq

    To examine o r p a t c h a u s u a l l y b i n a r y ) f i l e ,

    d b [ name [ n a m e l i s t ] ]

    The f i r s t argument ~ t h e f i l e t o be examined. The . second i s a

    name l i s t f i l e produced a s n . o u t when l l l l§. was assembled . The.

    b r a c k e t s i n d i c a t e t h a t b o t h a rgument s a r e o p t i o n a l . I f t h e f i r s t

    a rgumen t i s n o t g i v e n , ' ' .o r e i s assumed. I f t h e second i s n o t

    g i v e n ,.

    n . o u t i s assumed. Of c o u r s e , t h e f i r s t argument a l o n e

    c a n n o t be o m i t t e d . )

    Db i s d i s c u s s e d i n comple te d e t a i l i n Appendix 2 .

    ) § 2_ ed e d i t

    ED i s t h e e d i t o r o I t i s e s s e n t i a l l y a s u b s e t o f QED [ r e f e r e n c e s ] ;

    s e e Tl ppend i x 2 f o r t h e d i f f e r e n c e s .

  • 8/17/2019 UnixEditionZero OCR

    31/53

    - 31 -

    To c r e a t e a l i n k ,

    l n name 1 [ name 2 ]

    l i n k t o f i l e i s c r e a t e d . I f i s g i v e n , t h e l i n k h a s

    name ~ 2 o t h e r w i s e t h a s t h e ( l a s t component o f ) • For

    example , i n / a / b / c / d c r e a t e s a l i n k named d i n d i r e c t o r y

    - / c t o f i l e / a / b . The u s e r must have p e r m i s s i o n t o w r i t e i n/

    d i r e c t o r y / c .

    l s t d i r e c t o r y

    To l s t t h e names o f t h e f i l e s i n a d i r e c t o r y ,

    l s [ name ]

    I f lfil §. i s no t g i v e n , t h e c o n t e n t s o f t h e c u r r e n t d i r e c t o r y a r e

    l i s t e d .

    mkdir make d i r e c t o r y

    To c r e a t e a d i r e c t o r y ,\

    mkdir name

    move f i l e

    To move o r rename a f i l e ,

    v name 1 name 2 • • •

    T h i s command does n o t copy t h e f i l e . I t o p e r a t e s b y l i n k i n g t o

  • 8/17/2019 UnixEditionZero OCR

    32/53

    32

    1 by t h e name t h e n u n l i n k i n g 1 v i s o f t e n u s e d

    t o rename a f i l e .

    I f .fil : §. 2 i s a d i r e c t o r y , i s moved i n t o t h a t d i r e c t o r y under

    t h e name which i s t h e l a s t component o f For example ,

    mv x / d i r n a m e

    moves l t o / d i r n a m e / x .

    8 . 1 4 n -- g e t n a m e l i s t

    o g e t a p r i n t e d l i s t i n g o f t h e symbol t a b l e (name l i s t f rom anassembly,

    nm [ name ]

    where i s t h eI I H

    n . o u t f i l e f rom some assembly. I f .mllil.§. i s n o t

    g i v e n , " ". o u t i s l i s t e d .

    The command

    p r name 1 name 2 • • • narnen

    p r i n t s t h e con t en t s o f t h e named f i l e s . The o u t p u t i s s e p a r a t e d

    i n t o p a ges headed by t h e f i l e name, t h e t i m e and d a t e , and t h epage number.

    8 . 1 6 r n - - r e n ove f i l e

    ro unlinl

  • 8/17/2019 UnixEditionZero OCR

    33/53

    )

    l/

    - 33 -

    rm name 1 • • •

    R e c a l l t h a t removing t h e l a s t l i n k t o a f i l e c a u s e s i t t o go

    away

    g.11 r a f f r u n o f f f o r m a t )

    R o ff i s a program s i m i l a r t o t h e one u n d e r GE-TSS which f o r m a t s

    t e x t f i l e s under t h e c o n t r o l o f commands embedded i n t h e t e x t .

    The command

    r o f f narae 1 narnen

    w i l l r u n o f f t h e .c o n c a t e n a t i o n o f • • • ~ · UN X rof=

    s u p p o r t s a l l t h e f e a t u r e s o f TSS r o f f e x c e p t

    f o o t n o t e s . See [ r e f e r e n c e ] f o r d e t a i l s .

    8 j_Q sh - - Sh e l l

    To i n v o ~ et h e S h e l l ,

    s h [ name J

    erge t a b s , and

    Name i s i n t e r p r e t e d a s a f i l e o f commands. need n o t be

    g i v e n , i n which c a s e t h e S h e l l w i l l r e a d i t s s t a n d a r d i n p u t f i l e .

    When c a l l e d w i t h an a rgument , t h e S h e l l r e f r a i n s f rom t y p i n g i t s

    prom p t c h a r a c t e r • Se e s e c t i o n 5 abov e . Th e S h e l l h a s s e v e r a lf e a t u r e s b e s i d e s t h o s e ment ioned i n s e c t i o n s.

    1 . Arguments o r p a r t s o f argum e n t s t o coITuuands e n c l o s ed i n

    s i n g l e ( ' ) o r doub l e ( ) q u o t es a r e t a k e n l i t e r a l l y , so t h a t

    a r b i t r a r y c h a r a c t e r s t r i n g s can be p a s s e d ( i n c l u d i n g s p a c e s ,

  • 8/17/2019 UnixEditionZero OCR

    34/53

    \

    < )r > e tce o\. The c h a r a c t e r

    - 34 -

    s e r v e s t o quo te t h e n e x t c h a r a c t e r . In

    t h i s way a s i n g l e command may ex tend ove r s e v e r a l l i n e s ,

    s i n c e a new l i n e preceded by \ i s t r e a t e d l i k e a space .

    3 . When t h e S h e l l i s i nv o ked a s a command, t h e c h a r a c t e r s e -

    uences $ 0 , $1 , o~ a r e t r e a t e d as p a r a m e t e r s . $ 0

    i s r e p l a c e d by t h e name o f t h e f i l e b e i n g i n t e r p r e t e d ; 1H I I

    t h rough $9 a r e r e p l a c e d by t h e f i r s t t h rough n i n t h a r g u -

    ment f o l l o w i n g t h e f i l e name. For example , when

    sh runcom arg1 arg2 a rg3

    i s t yped , o . i n s i d e o f runcom i s r e p l a c e d by un com,

    .1 i s r e p l a c e d by a rg 1 , , e t c .

    B.19 s t a t a e t f i l e s t a t u s-To d i s c o v e r i n t e r e s t i n g i n f o r m a t i o n abou t one o r more f i l e s ,

    s t a t na.-r1e 1

    S t a t g i v e s t h e i -number, t h e mode, t h e owner, t h e s i z e , and t h e

    t i m e s o f c r e a t i o n and l a s t m o d i f i c a t i o n f o r each o f • • • •

    t a n rnan inu la te D SCTAPE

    Tap i s used t o l oad and dump p o r t i o n s o f t h e h i e r a r c h y on to

    DECTAPE. See Appendix 2 f o r d e t a i l s .

    To d i s c o v e r v a r i o u s i n f o r m a t i o n connec t ed w i t h t i m e , t h e tm co 1-

  • 8/17/2019 UnixEditionZero OCR

    35/53

    mand can be used :

    tm [ command a rg 1 • • •

    - 35 -

    a r q ]-n

    - I f c a l l e d wi thou t arguments , . :.ffi p r i n t s o u t t h e t i m e o f day and

    t h e t o t a l t i m e s accumula ted i n s e v e r a l c a t e g o r i e s :

    --

    _

    _

    1 . P r o c e s s o r t ime charged t o t h e u s e r .

    2 . System overhead t i m e .

    3 . Time s p e n t w a i t i n g f o r t h e d i s k .

    4 . I d l e t ime .

    ~ spen t i n t h e i n t e r r u p t r o u t i n e s .Without an argument , · En g i v e s t h e s e v a l u e s b o t h i n a b s o l u t e for.-:l

    ( . ~ . , t o t a l s s i n c e c r e a t i o n o f t h e sys tem) and a s changes s i n c e

    t h e l a s t t ime tm was c a l l e d . When c a l l e d w i t h one o r more a r -

    guments , t h e arguments a r e assumed t o c o n s t i t u t e a command t o b e

    t im ed . m execu t e s t h e g i v e n command and p r i n t s t h e t i m e s r e -

    q u i r e d f o r t h e c o m . ~ a n di n each o f t h e above c a t e g o r i e s .

    undef ined svmbols

    I t i s sometimes u s e f u l t o know t h e names o f a l l t h e u n d e f i n e d

    symbols i n a g iven assembly. The command

    un [ name ]

    s e a r c h e s t h e name l i s t f i l e and p r i n t s a l l t h e symbols u n -

    d e f i n e d t h e r e i n . I f name i s o ~ i t t e d . o u t i s used .

  • 8/17/2019 UnixEditionZero OCR

    36/53

    APPENDIX 1

    T h i s append ix summarizes a l l t h e sys tem c a l l s . To u n d e r s t a n d t h e

    c a l l s t o UNIX, t i s f o r t u n a t e l y n e c e s s a r y t o know o n l y v e r y l t ~

    t l e o f t h e s t r u c t u r e o f t h e ?DP-11. The machine con t a in s s e v e r a l

    g e n e r a l r e g i s t e r s o f which o n l y two a r e used f o r arguments t o

    t h e c a l l s namely RO and R1. There i s a l s o a c o n d i t i o n r e g i s t e r

    one o f whose b i t s r e c o r d s a c a r r y o c c u r r i n g d u r i n g an a r i t h m e t i c

    o p e r a t i o n . To i n d i c a t e an e r r o r t h e sys tem s e t s t h i s c a r r y b i t ;

    t i s c l e a r e d fo r s u c c e s s f u l c a l l s . There i s a c o n d i t i o n a l b r a n c h

    i n s t r u c t i o n t o t e s t t h e s t a t e o f t h e b i t . ~ r e g i s t e r s n o t used

    t o communicate e x p l i c i t arguments a r e unchanged by c a l l s t o t h e

    sys tem.

    I he i n s t r u c t i o n used t o c a l l t h e sys tem i s known t o t h e a s s e m b l e r

    s sys ; when t h e p roces so r e x e c u t e s t h i s i n s t r u c t i o n t i s

    t r a p p e d t o a s p e c i f i c l o c a t i o n i n s i d e UN Xo The a d d r e s s f i e l d o f

    y s c o n t a i n s a number i n d i c t i n g v:hic y t cc.11 i s desire ::.

    The a rgument s f o r a c a l l a r e p l a c e d e i t h e r i n a r e g i s t e r o r

    m m e d i a t e l y f o l l o w i n g t h e s y s i n s t r u c t i o n .\

    A number o f t h e c a l l s p r i n c i p a l l y t hose d e a l i n g w i t h t h e f i l e

    sys tem, t a k e s t r i n g s as agruments . There i s a s t a n d a r d fo rmat f o r

    such a s t r i n g : t c o n s i s t s o f a sequence o f b y t e s end ing i n a

    n u l l c h a r a c t e r . The 012en c a l l below, c o n t a i n s a comple te example

    o f how t o w r i t e such a s t r i n g .

  • 8/17/2019 UnixEditionZero OCR

    37/53

    )

    )/

    \

    A - 2

    E x i t i s u s e d t o t e r m i n a t e a p r o c e s s as f o l l o w s :

    s y s e x i t

    There a r e no a rg u m e n t s , n o r i s t h e r e e v e r any r e t u r n : :rom t h i s

    c a l l

    T h i s i s t h e p r i m i t i v e u s e d t o g e n e r a t e new p r o c e s s e s .

    s y s f o r ko l d p r o c e s s r e t u r n )new p r o c e s s r e t u r n )

    There a r e no i n p u t a rg u m e n t s . The 8 r r o r b i t i s s e t i no spac·e i s

    a v a i l a b l e t o c r e a t e a new p r o c e s s , and c o n t r o l r e t u r n s o n l y t o

    t h e o l d p r o c e s s . RO c o n t a i n s t h e p r o c e s s i d e n t i f i c a t i o n o f t h e

    new p r o c e s s . See a l s o s e c t i o n s.

    The .a r e n t p r o c e s s r e t u r n s i i l lmedia te ly a f t e r t h e sys c a l l ; t h e.

    new p r o c e s s s k i p s one w o r ~ The l a b e l r g u ~ e n tment ioned i n t h e

    d i s c u s s i o n o f f o r k i n s e c t i o n 5 . 5 w a s a w h i t e l i e . )

    To r e a d an open i l e whos e f i l e d e s c r i p t o r i s f i l ~ o l o a d i l eo

    i n t o

  • 8/17/2019 UnixEditionZero OCR

    38/53

    A - 3

    r e a d , and n c h a r s i s t h e maximu:n number o f c h a r a c t e r s d e s i r e d .

    (The a c t u a l number, n o t i t s a d d r e s s . ) The nurlber o f c h a r a c t e r s

    a c t u a l l y r e a d r e t u r n s i n RO. I f RO i s z e r o , t h e end o f t h e f i l e

    h a s b e e n r e a c h e d . The e r r o r b i t may be s e t i f f o r example , the ·/

    )

    f i l e i s a t a p e f i l e and t h e r e was a permanen t r e a d e r r o r , o r i f

    an a t t e m p t was made t o r e a d i n t o an a r e a n o t p a r t o f t h e u s e r s

    c o r e image.

    M.oi w r i t e

    To w r i t e an open f i l e w i t h f i l e d e s c r i p t o r f i l e p , l o a d f i l e o i n t o

    RO and

    s y s w r i t eb u f f e rn c h a r s

    where b u f f e r and n c h a r s a r e t h e same a s f o r r e a d . The number o f

    c h a r a c t e r s a c t u a l l y w r i t t e n r e t u r n s i n RO ( o r d i n a r i l y i t i s t h e

    same a s n c h a r s ) and e r r o r s a r e i n d i c a t e d by t h e e r r o r _b i t .

    To o p e n an a l r e a d y e x i s t i n g f i l e ,

    s y s opennamemode

    • • •

    narne: (pathname\O)

    i s t h e a d d r e s s o f a s t r i n g o f c h a r a c t e r s c o n s t i t u t i n g a p a t h

    name. The name i s t e r m i n a t e d by a n u l l ( a l l z e r o ) c h a r a c t e r ,

    which i s i n d i c a t e d by \o ; t h e c h a r a c t e r s < and > a r e s t r i n g

    q u o t e s . Mode i s O o r 1 t o i n d i c a t e r e a d i n g o r w r i t i n g r e s p e c -

  • 8/17/2019 UnixEditionZero OCR

    39/53

    A 4

    t i v e l y . The f i l e d e s r ~ p t o rr e t u r n s in RO. I f t h e f i l e c a n n o t be

    found o r i p e r m i s s i o n i s n o t g r a n t e d t h e e r r o r b i t i s s e t .

    - A .§. c r e a t

    To c r e a t e o r r e c r e a t e a f i l e ,

    s y s c r e a tnamemode

    i s t h e same as f o r open . Mode i s a number encod ing t h e p r o -

    t e c t i o n b i t s a s s p e c i f i e d under t h e chmod command below A 2.9 )o

    C r e a t i o n o f a f i l e i m o l i e s o p e n i n g f o r w r i t i n g ; t h e f i l e d e s c r i p -

    t o r i s r e t u r n e d i n RO.

    81_. 7 c l o s e

    To c l o s e a f i l e , move t h e f i l e d e s c r i p t o r i n t o RO and

    s y s c l o s e

    A program may have o n l y a l i m i t e d number o f f i l e s open a t one

    t i m e c u r r e n t l y , 1 0 ) . C l o s i n g a f i l e a l l o w s a n o t h e r f i l e t o be

    opened i n i t s p l a c e . C l o s i n g i s o t h e r w i s e u n n e c e s s a r y, f o r an

    a u t o m a t i c c l o s e on a l l f i l e s i s per fo rmed when t h e p r o c e s s t e r -

    \/

    m i n a t e s .

    To w a i t f o r a c h i l d p r o c e s s t o t e r m i n a t e ,

    s y s w a i t

  • 8/17/2019 UnixEditionZero OCR

    40/53

    A - 5

    The i d e n t i f i c a t i o n o f t h e t e rmina t ed p r o c e s s i s r e t u r n e d i n ROc

    At t h e p r e s e n t t i ~ no f u r t h e r i n f o r m a t i o n i s r e t u r n e d ; i n t h e

    f u t u r e a means o f d e t e r m i n i n g t h e f a t e o f t h e p r o c e s s w i l l b e

    p rov ided .

    \

    I f t h e p r oc es s execu t i ng a wai t has no l i v i n g c h i l d r e n , an e r r o r

    i s r e t u r n e d .

    To c r e a t e a l i n k i n an a r b i t r a r y d i r e c t o r y,

    s y s l i n kname 1name 2

    Name 1 and ~ a r e p o i n t e r s t o

    l i n k e d t o , and t h e l i n k h a s name

    ~ d o e s n o t e x i s t o r • -F1 ~

    A1.1.Q u n l i n k

    names a s i n

    lfil 1§. 2 • An

    does e x i s t .

    open .

    e r r o r

    To remove t h e name o f a f i l e f rom a d i r e c t o r y,

    s y s u n l i n kname

    F i l e ~ i s

    i s i n d i c a t e d • -F1

    Name i s a p o i n t e r t o a name. The s p e c i f i e d e n t r y i s removed from

    i t s d i r e c t o r y ; i t h i s was t h e l a s t e n t r y l i n k ) p o i n t i n g t o t h e

    f i l e , t h e f i l e i s d e s t r o y e d .

    To c a u s e e xecu t i on o f a f i l e as a program

  • 8/17/2019 UnixEditionZero OCR

    41/53

    s y s e x e cnamea rg p

    • • •

    A - 6

    a rg p : a r g 1a r g 2

    •••

    0

    The f i r s t argument i s t h e add re s s o f a f i l e name. The second

    argument i s t h e a d d r e s s o f a l i s t o f argument p o i n t e r s t e r m i na t ed

    by a z e r o p o i n t e r . Each argument p o i n t e r i s t h e a d d r e s s o f a

    s t r i n g t o be p a s s e d t o t h e command o r o t h e r program. The f i r s t

    argument p o i n t e r a rg 1 i s , by c o n v e n t i o n , t h e name o f t h e f i l e

    b e i n g invoked . When a program i s e x e c u t e d by t h e S h e l l , i t can

    d e t e r m i n e t h e name y which i t was c a l l e d . Thus one may w r i t e a

    · s i n g l e program w i t h s e v e r a l names which t a k e s v a r i o u s a c t i o n s

    a c c o r d i n g t o t h e name u s e d .

    A f i l e invoJ

  • 8/17/2019 UnixEditionZero OCR

    42/53

    A - 7

    To change t h e c u r r e n t d ~ r e c t o r y

    s y s c h d i rd i rname

    di rname p o i n t s t o t h e s t a n d a r d f o r m a t s t r i n g d e s c r i b i n g a

    d i r e c t o r y.

    The c a l l

    s y s t i m e

    r e t u r n s i n t h e AC and HQ r e g i s t e r s t h e number o f s i x t i e t h s o f a

    second s i n c e t h e s t a r t o f t h e c u r r e n t y e a r .

    A 1 . l l mkdir

    The c a l l

    s y s mkdirname

    c r e a t e s t h e f i l e whose name i s p o i n t e d t o by and marks t a s

    a d i r e c t o r y.

    A1.15 chmod

    The mode o f a f i l e i s changed by

    s y s chmodnamenewmode

    See t h e chmod command s e c t i o n 8 . 5 ) f o r t h e i n t e r p r e t a t i o n o f

    t h e mod e . o n l y t h e owner o f a f i l e may chang e t h e mode.

  • 8/17/2019 UnixEditionZero OCR

    43/53

    A1 - 8

    Mo 1 § ch own

    l/

    ' '

    To change t h e owner o f a f i l e

    sys chownname

    newowner

    Only t h e owner o f a f i l e may change i t s owner.

    To s a v e t ime , UNIX does no t swap a l l o f t h e K u s e r c o r e a r e a

    when exchang ing c o r e images . The l o c a t i o n s swapped a r e t h os e f rom

    t h e b e g i n n i n g o f t h e c o r e image t o t h e i n i t i a l program b r e a k , and

    f rom t h e t o p o f u s e r c o r e down t o t h e s t a c k p o i n t e r . The i n i t i a l

    program b r e a k i s d e t e r m i n e d by t h e s i z e o f t h e f i l e c o n t a i n i n g

    t h e programo The s y s t e m s i d e a o f how much t o swap may be a l t e r e d

    by u s i n g t h i s c a l l :

    s y s b r e a k

    newbreak

    .Newbreak becomes t h e f i r s t . l o c a t i o n no t swapped. f · i t p o i n t s

    beyond t h e s t a c k o r t o t h e v e r y f i r s t word i n t h e c o r e image,

    t h e e n t i r e c o r e image i s swapped.

    The u s e r may o b t a i n a copy o f t h e i - n o d e f o r a named f i l e :

    s y s s t a tnameb u f f e r

    i s t h e name o f a f i l e and b u f f e r i s t h e a d d r e s s o f 34

    s e q u e n t i a l b y t e s i n t o which i n f o r m a t i o n c o n c e r n i n g t h e f i l e i s

  • 8/17/2019 UnixEditionZero OCR

    44/53

    A 9

    p l a c e d See s e c t i o n 4 f o r what i n f o r m a t i o n i s p a s s e d ; c o n s u l t a

    UNIX programming c o u n c i l l o r f o r i t s f o r m a t .

    J ~ 1 9 s e e k

    \

    To move t h e r e a d o r w r i t e p o i n t e r a s s o c i a t e d w i t h t h e open f i l e

    w i t h f i l e d e s c r i p t o r f i l e p l o a d f i l e p i n t o RO and

    s y s s e e kb a s eo f f s e t

    s e e a l s o s e c t i o n 3.s.s.

    To d i s c o v e r t h e p o s i t i o n o f t h e r e a d o r w r i t e p o i n t e r a s s o c i a t e d

    w i t h t h e open f i l e w i t h f i l e d e s c r i p t o r f i l e p move f i l e p i n t o RO

    and

    s y s t l l

    b a s eo f f s e t

    The r e s u l t r e t u r n s i n RO. See a l s o s e c t i o n 3 . 5 . 6 .\

    A £ { u n a s s i q n e d )

    To c o n t r o l t h e h a n d l i n g o f r e a k s i g n a l s s e n t by t h e u s e r

    s y s i n t r

    I f RO i s z e r o on e n t r y i n t e r r u p t s a r e d i s a b l e d ; i f RO i s n o n -

    z e r o t h e y a r e e n a b l e d .

  • 8/17/2019 UnixEditionZero OCR

    45/53

    \/

    APPENDIX 2

    T h i s Appendix d i s c u s s e s i n more d e t a i l t h e u s a g e o f t h e

    a s s e m b l e r, t h e e d i t o r , t h e debuggerP and t h e DECTAPE m a n i p u l a t i o n

    command.

    a2 i s b a s e d on t h e DEC-provided a s s e m b l e r P ~ L 1 1 [ r e f e r e n c e s ] f

    a l t h o u g h i t was coded l o c a l l y . T h e r e f o r e , o n l y t h e d i f f e r e n c e s

    w i l l b e r e c o r d e d .

    C h a r a c t e r changes a r e :

    f o r u s e@ *

    $; I

    H t •

    In ~ t h e c h a r a c t e r ; . i s a l o g i c a l new l i n e ; s e v e r a l o p e r a -

    t i o n s may a p p e a r on one l i n e i s e p a r a t e d by

    e x p r e s s i o n o p e r a t o r s have been p r o v i d e d :

    \ )\<*\ /\1[]

    r i g h t s h i f t ( l o g i c a l )l e f t s h i f tm u l t i p l i c a t i o nd i v i s i o n

    r e m a i n d e ro n e s complement u n a r y )p a r e n t h e s e s f o r g r o u p i n g

    There i s a c o n d i t i o n a l assembly o p e r a t i o n code :

    e i f e x p r e s s i o n

    0

    • e n d i f

    • . S e v e r a l new

  • 8/17/2019 UnixEditionZero OCR

    46/53

    A

    I f t h e e x p r e s s ion e v a l u a t e s t o n o n - z e r o , t h e s e c t i o n o f code

    I

    be tween .h e i f and t h e . e n d i f i s assembled ; o t h e r w i s e i t i s

    i d · ~ b dnore • i ~ s may e n e s t e •

    Temporary l a b e l s l i k e t h o s e i n t r o d u c e d b y Knuth [ r e f e r en c e ] may

    be employed. A t empora ry l a b e l i s d e f i n e d a s f o l l ows :

    n :

    nwhere l l i s a d i g i t O • • • 9 . Symbols o f t h e fo rm n f r e f e r t o t h e

    f i r s t l a b e l nu: f o l l o w i n g t h e u s e o f t h e symbol ; t h o s e o f t h eform nb r e f e r t o t h e l a s t n : . he same l l may be u s e d many

    t i m e s . L a b e l s o f t h i s form a r e l e s s t a x i n g bo t h on t h e i m a g i n a -

    t i o n o f t h e p r o g r a m ~ e rand on t h e symbol t a b l e space o f t h e

    a s s e m b l e r.

    The PAL-11 opcodes e o t and ~ e n d a r e r e d u n d a n t and a r e o m i t -

    t e a .

    The symbols

    rO 0 r sSpp ca cmqd i vmull s ha s hn o rcsw

    a r e p r e d e f i n e d w i t h a p p r o p r i a t e v a l u e s e

    Th e .e w o p c o de sys i s u s e d t o spe c i f y s y s t em c a l l s . Na me s f o r

    s y s t e m c a l l s a r e p rede f inedo Se e Appendix 1 f o r t h e l i s t o f

    c a l l s .

  • 8/17/2019 UnixEditionZero OCR

    47/53

    A

    S t r i n g s o f c h a r a c t e r s r a ~ ybe assembled i n a way more c o n v e n i e n t

    t h a n P.f\.L-11 ' s . a s c i i o p e r a t i o n (which i s , t h e r e f o r e , o m i t t e d ) .

    t . . 1 d d b h < d > .r i n g s a r e i n c u e etween t e s t r i n g quo t e s an •

    ( h e r e i s a s t r i n g )

    Escape sequences e x i s t t o e n t e r non g r a p h i c and o t h e r d i f f i c u l t

    c h a r a c t e r s . These sequences a r e a l s o e f f e c t i v e i n s i n g l e and

    double c h a r a c t e r c o n s t a n t s i n t r o d u c e d by s i n g l e and doub le q u o t e s

    r e s p e c t i v e l y . r e s p e c t i v e l y :

    \

    u se f o r

    \ n n e w l i n e (012)\ 0 NULL (000)\> >\ t TAB (011)

    When e r r o r s occu r, a s i n g l e - c h a r a c t e r d i a g n o s t i c i s typed o u t

    t o g e t h e r w i t h t h e l i n e number and t h e f i l e name i n which t

    occu r r ed . Er ro r s i n p a s s 1 c a u s e c a n c e l l a t i o n o f p a s s 2 . The

    p o s s i b l e e r r o r s a r e :

    )]*0

    pa ren the se s e r r o rp a r e n t h e s e s e r r o rI n d i r e c t i o n ( ~ ) u s e d i l l e g a l l y~ ( t h e l o c a t i o n cou n t e r ) ha s become u n d e f i n e de r r o r i n Addressg r a n c h i n s t r u c t i o n h a s t o o r emote an a d d r e s se r r o r i n Exoress ione r r o r i n l o c a l ( .[ o r b ) t y p e symbolGarbage (unknown) c h a r a c t e rl i u l t i p l y de f ined symbol a s l a b e l

    ABEFGM

    0p

    Qdd- - word q u n t ~ t yassembled a t odd a d d r e s sPhase e r r o r - - • d i f f e r e n t i n p a s s 2 f rom pas s 1

    v a l u eRux

    Re loca t i on e r r o r~ n d e fi n e d symbolsynta2£ e r r o r

    The b i n a r y o u t p u t o f t h e a s s e m b l e r i s p l ace d on t h e f i l e . o u t

    i n t h e c u r r e n t d i r e c t o r y . The a s s e m b l e r a l s o g e n e r a t e s a f i l e

  • 8/17/2019 UnixEditionZero OCR

    48/53

    ~

    A4

    n . o u t which i s a copy o f t h e name l i s t f rom t h e assembly, t h a t

    i s , a t a b l e o f t h e names o f symbols used and t h e i r v a l u e s .

    . o u t i s used by t he db , nm and un commands.

    The a s s e m b l e r does not produce a l i s t i n g o f t h e s o u r c e programe

    This i s n o t a se r ious drawback; t h e debugger db d i s cus sed below

    i s s u f f i c i e n t l y power fu l t o r e n d e r a p r i n t e d o c t a l t r a n s l a t i o n o f

    t h e s o u r c e u n n e c e s s a r y.

    Unl ike many debugg ing packages i n c l u d i n g DEC's ODT on which db

    i s l o o s e l y based) db ·i s n o t l o a d e d a s p a r t o f t h e c o r e i mage

    which i t i s used t o examine; i n s t e a d i t examines f i l e s . Ty p i -

    c a l l y , t h e f i l e w i l l be e i t h e r a c o r e image produced a f t e r a

    f a u l t ( s e e s e c t i o n 7) o r t h e b i n a r y o u t p u t o f t h e assembler. db

    i s c a l l e d a s f o l l o w s :

    db [ name [ n a m e l i s t ] ]

    Name i s t h e f i l e b e i n g debugged; i omi t t ed c o r e assumed.,s

    n a m e l i s t i s t h e n . out•• f i l e p roduced when was assembled; i

    o m i t t e d ,.

    n . o u t i s assumed. I f no a p p r o p r i a t e name l i s t f i l e can

    be f o u n d , db can s t i l l b e u s e d bu t so me o f i t s symbol ic f a c i l i -

    t i e s become unav a i l a b l e .

    The fo rmat f o r most db r e q u e s t s i s an ad d r e s s f o l l o w e d by a one

    c h a r a c t e r co mma nd o

    Addresses a r e exp re s s ions b u i l t up a s f o l l o w s :

    1 . A nam e h a s t he va lue a s s i g n e d t o i t w:. e n t h e i n p u t f i l e :: 2 s

  • 8/17/2019 UnixEditionZero OCR

    49/53

    )

    S

    assembled . t may be r e l o c a t a b l e o r n o t depend ing on t : Y=

    u s e o f t h e name d u r i n g t h e assembly.

    2 . n o c t a l number i s an a b s o l u t e q u a n t i t y w i t h t h e a p p r o p r i -

    a t e v a l u e .

    3 . o c t a l number i m m e d i a t e l y f o l l o w e d by i s r e l o c a -n r a

    t a b l e q u a n t i t y w i t h t h e a p p r o p r i a t e v a l u e .

    4 . The symbol • i n d i c a t e s t h e c u r r e n t p o i n t e r o f db. The

    c u r r e n t p o i n t e r i s s e t by many db r e q u e s t s .

    5 . Express ions s e p a r a t e d b y + o r ( b l a n k ) a r e exp r e s s ions

    w i t h v a l u e e q u a l t o t h e sum o f t h e components . At most one

    o f t h e components may be r e l o c a t a b l e .

    Se E x p r e s s i o n s s e p a r a t e d b y- - :term an e x p r e s s i o n -.;ntn va lue

    e q ua l t o t h e d i f f e r e n c e t o t h e components . I f t h e r i g h t

    component i s r e l o c a t a b l e , t h e l e f t component must be

    r e l o c a t a b l e .

    7 . E x p r e s s i o n s a r e e v a l u a t e d l e f t t o r i g h t .

    I f no a d d r e s s i s g i v e n f o r a command, t h e c u r r e n t a d d r e s s ( a l so

    s p e c i f i e d by t ) .• i s a s s u m ~ d

    word o r b y t e printec" . by d b .

    In g e n e r a l , • p o i n t s t o t h e l a s t

    There a r e db commands f o r examining l o c a t i o n s i n t e r p r e t e d as

    o c t a l numbers , machine i n s t r u c t i o n s , ASCII c h a r a c t e r s , and

    a d d r e s s e s . For numbers and c h a r a c t e r s , e i t h 8 r b y t e s o r words may

    be examined . he f o l l o w i n g commands a r e used t o examine

    s p e c i f i e d f i l e .

    The a d d r e s s e d Hord i s p r i n t e d i n o c t a l .

    \ The a d d r e s s e d b y t e i s p r i n t e d i n oct?. . l .

    he a d d r e s s e d word i s p r i n t e d as two ASCII c h a r a c t e r s .

  • 8/17/2019 UnixEditionZero OCR

    50/53

    )

    A6

    ,The a d d r e s s e d by t e i s p r i n t e d a s an ASCII c h a r a c t e r .

    ? The a d d r e s s e d word i s i n t e r p r e t e d a s a machine i n s t r u c t i o n

    and a symbol ic form o f t h e i n s t r u c t i o n , i n c l u d i n g symbol i c

    a d d r e s s e s , i s p r i n t e d . U s u a l l y, t h e r e s u l t w i l l a p p e a r

    e x a c t l y a s i t was w r i t t e n i n t h e s o u r c e program.

    The a d d r e s s e d word i s i n t e r p r e t e d as a symbol ic a d d r e s s and

    i s p r i n t e d a s t h e name o f t h e symbol whose v a lu e i s c l o s e s t

    t o t h e a d d r e s s e d word, p o s s i b l y f o l l o w e d by a s i g n e d

    o f f s e t .

    ( n l ) ( i . e . , t h e c h a r a c t e r new l i n e ) T h i s com.rnand advances

    t h e c u r r e n t l o c a t i o n c o u n t e r . and p r i n t s t h e r e s u l t i n g

    l o c a t i o n i n t h e raode l a s t s p e c i f i e d by one o f t h e above

    r e q u e s t s .

    T h i s c h a r a c t e r decrements • and p r i n t s t h e r e s u l t i n g

    l o c a t i o n i n t h e mode l a s t s e l e c t e d one o f t h e above

    r e q u e s t s . I t i s a c o n v e r s e t o ( n l ) .

    t i s i l l e g a l f o r t h e w o r d - o r i e n t e d corrunands t o have odd.

    a d d r e s s e s . The n r e m e n t ~ n gand d e c r e m e n t i n g o f • ·done by t h e

    ( n l ) and .. r e q u e s t s i s by one o r two d e p e n d i n g on whether t h e

    l a s t coramand was word o r ~ y t e o r i e n t e d .

    The a d d r