:





      2    .   -
       " "  -
,          -
.   6.1        
UNIX           . 
   ,      
     .     -
 ,     . -
           
 .    ,      
      ,    -
   .    6.2    
       ,   -
        
  .  6.3      
  ,        -
.  6.4 ,        
       ,    
 ,       -
 .   6.5    ,  -
    ,     -
           . , , 
 6.6      
.




         2,        
    ,  .   
    :
 1.     .
 2.     .
 3.   ,       .
 4.       .
 5.    ,    ( )  
          ,     
      .        9
       .
 6.           -
    ,         .
 7.       ( )  -
     ( ),      
      .       3 (
     )   .
 8.        ;  -
    ,     ,    .    
        ,  .
 9.      exit   . -
    ,    ,     ,    
     ,   .  -

                                    137

         .  6.1 
       
    .      -
  . ,     ,  
         ,    


                                      
                                      
                                       +-------+
                                       |   1   |
                            - |       |
                           , - ++------+
                                   | ^   ^
                - +-----+  +-------+ |   |
                , |     |  | +-------+   +---+  
                |     |  | |        |  
                 -|     |  | |               |
                  -|     v  v | -    |
      +-------+     |   +------++  -   ++------+
      |       |        +-->|       |       |       |
      |   9   |<-----------+   2   +------------>|   7   |
      |       |       |       | -|       |
      +-------+            ++------+           +-------+
                 |     ^                  - -
               |     |                  - 
            +---------------+     +------+    --------
            |            |    -
            v                            |    -
  -+-------+                        +-+-----+  
  - |       |           |       | 
  - |   4   +----------------------->|   3   |  
  -|       |                        |       |
   +---+---+                        ++------+
   -   |                             |  ^  ^
      |                             |  |  |  
          |                             |  |  |  
          |                             |  |  +---+
          | -                  -    |  |      |
          |                 |  |      |  
          |                             |  |-  ++------+
          |                             |  |-|       | fork
          |                             |  |   |   8   |<-----
          |                             |  |     ++------+
          |                             |  |      | -
          |                             |  |  +---+ 
          |                             |  |  |     
          |                             |  |  |  ( 
          |                             |  |  |   )
          v                             v  |  v
      +-------+                        +---+---+
      |       |           |       |
      |   6   +----------------------->|   5   |
      +-------+                        +-------+
      ,                     ,
                               

     6.1.       -
                 

                                    138


    .     
         -
 fork;          -
     (3  5).   ,    
 "    " (3).      -
            
"   ",     ,   -
 fork.
            "  
".        -
           "-
   ".       
,        , -
      "",   -
  .   ""    
  "    " (     ,
     ,   ), 
    ,  ,  , -
   ,       ,  
     . ,     -
       "".  
            
 "   ".
         ,    "-
      "     "   ".
,     -       
     -.    -
 "  ",       ,    
       -.  - ,
        
       ,    
   "    ".
    ,     ,  -
       ,    
( )   ,     
,       "  ,  ". 
,    ,         .
         
 ,      "  
 ".          -
  "    ".   ,  
  exit,      "  
 " , ,   " ".
                   .
-,      .   ,   
       (..   "  -
,   "    "  ,   -
")     .     . --
,       ,   
    "   "   "  
",          .   ,
         ;    
-             -
   " " (.  7.2,  -
  ). ,       exit 
  ,    ,    -
           exit.  -


                                    139

       ,  -
    ,     ,    
  ,      . -
    : , ,    
 ,   .
          :   -
    .    , -
     ,    - ,  -
          . 
          :
      ,       
 .
           :
  *  ,    .
  * ,            
         .      
       ,      
    "  ,   "   "  
    "    ""   "  
    ".    ,       -
          (   "  "  
      "").      
    ,        -
       .
  *      (UID),  -
      .  UID, ,    
    ,    (.  ).
  *   (PID),    .
        PID       ""
        fork.
  *   ( ,   ).
             -
      sleep  wakeup.
  *  ,      
        "   "   "-
       ".
  *  ,    ,   ,  
       ( 7.2).
  *  ,      
               -
       .       -
    ,         
       ( 8.3).      
    ,        .  
               -
     ,       :
  *    ,   , -
     .
  *    ,    
    ,  ,     (.  7.6).
  *  ,     (  )  -
         .
  * ,     .
  *   ,   "  -
    ",    .
  *  ,    ,    
     .
  *      ,     
    .

                                    140

  *  -:   ,    (
    )        ,     (
      -)  ..
  *      ,    ,
       .
  *       ,   ,
     .
  *  ,       -
        ,      .
  *   ,        -
    ,    .     -
              -
    .       , 
    ,  ,    .  -
             ;  
             -
     ,       "-
       ", "     ",  ""  
    "  (  )".        
    ""  " ",    8 -    "-
        ".   9    -
          .




    ,         ,   0 
 ,     .      2,
   UNIX     : ,    
.  (  ,      11,   
    ).        -
  ,     ;   
    (        -
),   (    )   -
  (      ,    -
).           
,        ,    -
.     ,    -
  ,          , -
    ,      
.    ,     -
      ,      -
 ,           
     .
             -
  ,       ,  
 ,   ,  -
,      ,    .  
 ,          
.   ,      
 :    ,      -
 ,       .  -
    ,     
  ,    .




        V       -

                                    141

  .  -     
   ,     -
     .  , ,  
     ,  . 
        . ,  
      ,  ,    -
       .   ,   -
       .
               -
      .   6.5    -
      ,      -
,     ,   -
    .     -
  .     ,  
   ,   ,    -
     ;   ,    -
    .      -
           
     .    
     .    
     ,     , -
 :  ,     . 
           
   :     
    ,  ,    
    ;         
      ,     
 ,       -
     ,  .
      6.2   , A  B,   , -
     ,     -
.     'a'     8    4
.    A      8,  


                             
                 
           ( )           +--------+
       -+--------------+             |        |
           |      8      +-----+   +-->|    b   |
  -+--------------+     |   |   |        |
   A      |     16      +-----|---+   +--------+    +--------+
             +--------------+     |                     |        |
         |     32      +-----|-------------------->|    c   |
             +--------------+     |       +--------+    |        |
                                  +------>|        |    +--------+
                                          |    a   |
       -+--------------+     +------>|        |
           |      4      +-----+       +--------+    +--------+
  -+--------------+                           |        |
   B      |      8      +-------------------------->|    e   |
             +--------------+             +--------+    |        |
         |     32      +-----+       |        |    +--------+
             +--------------+     +------>|    d   |
                                          |        |
                                          +--------+

                   6.2.   


                                    142

B     4,             
'a'.         .
      ,      
    .     -
 ,       -
    .   -
       9    -
      .        -
  : ,  ,     
  .  ,        -
    ( 9),      
,     ,   ,   -
,    ,     
  .




          ,     
      ,     
 UNIX.   ,     ,  
          ,  .
     512   4    -
  .      
  , ,     
 ( ,      ).  ,  
     2  32-  ,    1
,    - 2  22- ;    ,    
32-     22-    10-
   ( 6.3).
          ,  
       -   
   .      -

   +------------------------------------------------------------+
   |                   58432              |
   |                                                            |
   |                        0101 1000 0100 0011 0010    |
   |                                                            |
   |  ,                                    |
   |                 01 0110 0001    00 0011 0010 |
   |                                                            |
   |             161          32       |
   +------------------------------------------------------------+

        6.3.     


      +------------------------------------------------------+
      |        |
      |                                                      |
      |             0                          177           |
      |             1                           54           |
      |             2                          209           |
      |             3                           17           |
      +------------------------------------------------------+

     6.4.       


                                    143

    ,      
       .    
 ,       ,   -
       ( -
)  .
            -
           
        ,    
  6.4.       -
 ,        -
   .      
       ,   . 
   - ,     -
      .      -
      ,          
.
       6.5       
.     1       -
       ,    68432.  
 ,        -  65536  (64),
  ,        . 
     68432      -
,  2896.       1 ,  -
   848  2- (  0)  , 
   986.   6.5.5 (     -
)  ,         "-
".
             
,        -
            
 .   ,     
       
 , 

                   
                              ( )
          +--------------+
   |      8      +--------------+
          +--------------+              +-------->+--------------+
    |     32      +-------+                |         |
          +--------------+       |                +--------------+
      |     64      +---+   |                |    137      |
          +--------------+   |   v                +--------------+
            |   +--------------+ |    852      |
                             |   |     87      | +--------------+
                +------------+   +--------------+ |    764      |
                v                |    552      | +--------------+
                +--------------+ +--------------+ |    433      |
                |    541      | |    727      | +--------------+
                +--------------+ +--------------+ |    333      |
                |    783      | |    941      | +--------------+
                +--------------+ +--------------+ |       -      |
                |    986      | |   1096      | |       -      |
                +--------------+ +--------------+ |       -      |
                |    897      | |   2001      | |       -      |
                +--------------+ +--------------+ +--------------+
                |       -      | |       -      |
                +--------------+ +--------------+
    6.5.     

                                    144



            
.         -   
  -,        .  
,        ,  
.
             
.       1  , 
       .  -
       ;     -
      ,      
    ,      , 
   ,       
       ( ,   ). 
    .      -
  ,      -
      .
             ,   
   ,   -
. ,      16  (  6.5),  
     26,   -
,      .     , 
    ,      ,
,         .  
,        (    
 ).




      ,      ,  -
  ,   ,     -
.            
  .      -
           -
     .     -
  ,    ,   ,
          ,  -
     .    -
       ,  
     ,      -
  .          -
 ,          .  -
,          -
       ,    -
         ,    
         .     -
   ,       
    .
        6.6    ,      0 
4-1  ,    4 - .    -
  ,           ,
     ,   -
        .    -
          -
; ,         -
 ,         -


                                    145

   .
             ,  -
           -
          
.    ,      ,  ,
       .

                             -    -
                                       -
                                                  
                         +-----------+------------+-----------+
            1 |     --------+    0     |           |
                         +-----------+-|----------+-----------+
            2 |     ---+  | |   1     |           |
                         +--------|--+-|----------+-----------+
            3 |     --+|  | |   2     |           |
                         +-------||--+-|----------+-----------+
        1 | +---  ||  | |   4     |           |
                         +-|-----||--+-|----------+-----------+
        2 | |+--  ||  | |          |           |
                         +-||----||--+-|----------+-----------+
        3 | ||+-  ||  | |          |           |
                         +-|||---||--+-|----------+-----------+
  +------------------------+||   ||    |
  |          +--------------+|   |+----|-------+
  |          |          +----+   +-----|-------|----------+
  |          |          |           +--+       |          |
  v          v          v           v          v          v
  +------+   +------+   +------+    +------+   +------+   +------+
  | 856K |   | 747K |   | 556K |    |  0K  |   | 128K |   | 256K |
  +------+   +------+   +------+    +------+   +------+   +------+
  | 917K |   | 950K |   | 997K |    |  4K  |   |  97K |   | 292K |
  +------+   +------+   +------+    +------+   +------+   +------+
  | 564K |   | 333K |   | 458K |    |  3K  |   | 135K |   | 304K |
  +------+   +------+   +------+    +------+   +------+   +------+
  | 444K |   |   -  |   | 632K |    | 17K  |   | 139K |   | 279K |
  +------+   |   -  |   +------+    +------+   +------+   +------+
  |   -  |   |   -  |   |   -  |    |   -  |   |   -  |   |   -  |
  |   -  |   |   -  |   |   -  |    |   -  |   |   -  |   |   -  |
  +------+   +------+   +------+    +------+   +------+   +------+

                     
            ()

      6.6.       (
                 )   ( )





         ,    -
       ,      
 .           
  ,        . 
    'u' (   )
    .     
,      ,        (
6.4.3).     ,     

                                    146

   ,    ,  
        -
     .      
         , -
   .
           ,    
,   ,     .     -
        , 
   ,     -
  ,     .     
,        -
       .

                              -    -
                                        -
                                                   
                          +-----------+------------+-----------+
             1 |           |            |           |
                          +-----------+------------+-----------+
             2 |           |            |           |
                          +-----------+------------+-----------+
(-      3 |     ---+  |     2M     |     4     |
                   +--------|--+------------+-----------+
 )                         |
                                   +---------------------+
                                                         |
                   |
                                                         v
    +------+          +------+         +------+          +------+
    | 114K |          | 843K |         |1879K |          | 184K |
    +------+          +------+         +------+          +------+
    | 708K |          | 794K |         | 290K |          | 176K |
    +------+          +------+         +------+          +------+
    | 143K |          | 361K |         | 450K |          | 209K |
    +------+          +------+         +------+          +------+
    | 565K |          | 847K |         | 770K |          | 477K |
    +------+          +------+         +------+          +------+
     A          B         C          D

       6.7.      


    , ,      4  
    2.   6.7    ,
             (-
    ),       -
 D.        A,   
        
   .        
 ,        ,
       .    1
 2   ,      -
   .




             -
,   ,       -

                                    147

     .    , 
     ,   
  (*).       
,          
    .     -
  ,         
    ,     -
 .
         :
  *  ,    ,   -
        ;     
         .
  *    (PS),     
           .  PS, ,  
    ,  ,       
    ,    ,     -
        .. ,     PS,
       , -   PS  -
           .      
         PS    -
     ,        -
     ( /).        
      ,      
          .
  *   ,       
        ,      -
    .          -
              
    .        -
      (    ),       -
    .
  *   ,    , -
            .   
    ,      -  0   1 - 
           
    .     " " ( 
       )  " "  (  
    ).        -
           ,   
       .    -
        
    ,      ,  -
                
    .       :
  *     ,    ( 6.1)
        ,     -
     .
  *    ,  ,    
        ,     -
    .   ,    ,  
        ,       
      .

---------------------------------------
(*)            "  "
    (user-level  context),  " " (register context), "-
     " (system-level context)  " "  (context
    layers)  .


                                    148

  *     ,      -
     ,       -
    ,          , ,  
     ,  .    -
       ,       -
      ,       -
        .      
          , 
       .
  *  ,      ,    -
       .   ,     
          ,       
            . ,
    ,      creat      
          ,     
    read          
      .              
        ,     
     .      -
              , 
          .      
           ,   
     - ,  ,     -
      .      ,
        .
  *      ,   -
         ,        
    ,       .    
      ,    -
             .

              ,
           .
        -
,          -
,    .  ,    
          ,   
  :         ,
        . , -
     ,     
 .
      6.8    .   -
       .   : 
,    
( ), ,     (    -
),          ,   
 ,        
(,      -
  ).         .
         ,   -
           . 
     ,   -
 ;         
,   . ,    -
         -
,    ,       , 
     .



                                    149

            
   +-------------------------+ - |        -       |
   | |  - |        -       |
   | +---------------------+ |  |        -       |
   | |    | |   |        -       |
   | |               | |+-------->+----------------+
   | |                 | || - |     |
   | |    | ||    |    3     |
   | +---------------------+ ||  |                |
   |                         ||         |  -|
   |         || 3|  - |
   |      ||         |   2 |
   | +---------------------+ ||         +----------------+
   | |   - | ||         |     |
   | |               +-++         |    2     |
   | | | |          |                |
   | |   - | |          |  -|
   | |       | |  2|  - |
   | +---------------------+ |          |   1 |
   +-------------------------+          +----------------+
                                        |     |
                                        |    1     |
                                        |                |
                                        |  -|
                                1|  - |
                                        |   0 |
                                        +----------------+
                             |                |
                                 | (- |
                                   0|   ) |
                                        +----------------+

             6.8.   

          ,     
,       .  
          .
,            -
, , ,        ,
    5   , , ,     
 7  :      ,  1  
    1   . 7   -
,       ""   -
,      (     -
    )   ,    -
       .
      ,      - -
,  ,       ,    
     . ,   , -
    ,     
         
 ,       .  -
        
    ,        .




          ,    ,  

                                    150

   .  ,   ,   
 ,        
  .      -
   .




         ,     -
  (,      ),   (
   ,   " -
")      (      -
  ).        
       ,     -
      ,   
 ,       (    )
           ,     
,         
 .        -
 :
 1.        
      (  )   .
 2.   "" ,    (-
    ,      )   , -
      (,       
    ).          
    ,          -
    .       , , 
    ,       , -
        ,        
    .          ,
        6.9.     ,
         ,  2,   -

            +-----------------------------------------+
            |        |
            |                               |
            |                                         |
            | 0                   clockintr           |
            | 1                   diskintr            |
            | 2                   ttyintr             |
            | 3                   devintr             |
            | 4                   softintr            |
            | 5                   otherintr           |
            +-----------------------------------------+

               6.9.   


        ,  ttyintr.
 3.    .      
    ,    ,      -
      .      
        ,  
     ,         -
      ,      -
       .
 4.          .  -
            

                                    151

           ,   
      ,     
      .        
     ,          
            -
    . ,     ,    -
       .

      +-----------------------------------------------------+
      |  inthand    /*   */      |
      |  :                      |
      |  :                     |
      | {                                                   |
      |     (  )   |
      |     ;                                        |
      |      ;                  |
      |      ;                         |
      |       ;          |
      |     (  )  -  |
      |      ;                               |
      | }                                                   |
      +-----------------------------------------------------+

             6.10.   


      6.10  ,      -
.        -
         
   ,      ,
   ,      -
      ,   -
.     ,    -
  UNIX,  -.
      6.11  ,     
  (.  )       
 .      ,  -
           
 .  ,     (  -
 ),           
   .



               

              -
 ,       . ,   
         -
         .     -
  ,          
,         -
       .     -
 ,         -
       .    -
   "   ". 
    ,      -
          


                                    152

    
                                 +-------------------------------+
                                 |      3  |
                                 |     -   |
                                 |       |
                                 |                               |
                                 |     -  |
                                 |        |
                                 |              |
      --------+-------------------------------+
              ^                  |      2  |
              |                  |     -   |
              |                  |         |
              |                  |                               |
              |                  |     -  |
              |                  |       |
              |                  |                        |
      ----------+-------------------------------+
              ^                  |      1  |
              |                  |      -  |
              |                  |                  |
              |                  |                               |
              |                  |     -  |
              |                  |         |
              |                  |                         |
      ------+-------------------------------+
              ^
              |
              |
      

                 6.11.  


     .   
       -  
-        ,  
 ,    -       -
 .
        ,     
         -
,      ,    
  (  6.12).    () 
 ,  ( ,     -
 )          (  
    ). ,      -
       ,    
  .         ,   
.   ,       -
   ,     PS  -
   ,       .   -
     ,       PS  
         0  1  -
   .     
      ,     
    .   -
        -
.


                                    153

    +------------------------------------------------------------+
    |  syscall   /*     */|
    |  :                   |
    |  :              |
    | {                                                          |
    |          , -|
    |         ;                        |
    |       ,  ;|
    |           |
    |        ;                              |
    |             |
    |      (.  6.44);                                    |
    |           ;    |
    |      (     )    |
    |     {                                                      |
    |              -   |
    |            ;             |
    |             PS     |
    |           ;                     |
    |     }                                                      |
    |                                            |
    |              0 |
    |          1     ;    |
    | }                                                          |
    +------------------------------------------------------------+

         6.12.     

        ,     -
            (  0666) 
      6.13.      
       
  (      
 )   Motorola 68000.   6.14   -
      .   -
      ,      -
     (0666),   -  " " (**). 
  64     creat ( 7a),  -
    .      -
6a,      .   creat -
   0  8     (trap),  
           -
   . ,     , -
     0   (8)    , 
  creat.   ,    ,
   creat   ;  -
    ,     -
    .  ,   -
    ,        -
 .         creat  
        , 
,        (  
      );  ,   -
   PS  ,    0    
  .    ,   0  1    -
.  -
---------------------------------------
(**) ,           
       ,    .

                                    154


            +----------------------------------------+
            | char name[] = "file";                  |
            | main()                                 |
            | {                                      |
            |      int fd;                           |
            |      fd = creat(name,0666);            |
            | }                                      |
            +----------------------------------------+


+---------------------------------------------------------------+
|        ,        |
|                      Motorola 68000                    |
|                                                               |
|                                                   |
|       -                                                       |
|       -                                                       |
| #                                        |
|       -                                                       |
| 58:    mov    &Ox1b6,(%sp)    #   0666       |
| 5e:    mov    &Ox204,-(%sp)   #      |
|                               #    " "|
|                               #                          |
| 64:    jsr    Ox7a            #       |
|                               #                  |
|       -                                                       |
|       -                                                       |
| #                        |
| 7a:    movq   &Ox8,%d0        #   8   0|
| 7c:    trap   &Ox0            #   -|
|                               #                   |
| 7e:    bcc    &Ox6 <86>       #    ,     |
|                               #    86          |
| 80:    jmp    Ox13c           #    13c         |
| 86:    rts                    #          |
|       -                                                       |
|       -                                                       |
| #                                  |
| 13c:   mov    %d0,&Ox20e      #    |
|                               # 0   20e (    |
|                               # errno)                        |
| 142:   movq   &-Ox1,%d0       #    0  |
|                               # -1                            |
| 144:   mova   %d0,%a0                                         |
| 146:   rts                    #          |
+---------------------------------------------------------------+

     6.13.   creat   -
                       Motorola 68000


          -
,           PS
(   7):   ,     13c, 
         
errno   20,   0  -1,      
    64 (   ) .  -
    -1,          

                                    155

 .       PS    
       ,    7  
 86      ( 64);   0
   .

   +---------+                                |         -        |
   |    -    |                                |         -        |
   |    -    |                                |         -        |
   |    -    |                                |   -|
   |    -    |                                |  1|
   +---------+                                |                  |
   |   1b6   |                ||
   |         | (666   )   |  |
   |   204   |   " "   |   creat   |
   |    6a   |         +------------------+
   |         |       | -|
   +---------+<-----+                         |    |
   | -|      |                         |     0   |
   |  -|      |                         |(- |
   |  |               |       )        |
   |        |         -       |                  |
   |    7c   |        -     |   , |
   +---------+             |   |
                            |       7e         |
                               |                  |
        |                                     |  |
        |                                     |             |
        v                                     |                  |
                                              |     PS    |
                                              |                  |
                                              | 0 (|
                                              |    8)    |
                                              |                  |
                                              |    |
                                              |  |
                                              +------------------+

     6.14.      creat


              
  .         
        ,     
   . , ,    -
    exec,   execl  execle,   
     .  , 
 ,        ,
   ,        .




          ( 6.1),  -
,         -
:        ,   ,
         ,    
     ,      
     ,        
    .       2,  -

                                    156

          ,
    .    ,
       :   
 ,     ,    -
  ,    ,  -
     ,     
  .. ,    ,      -
       ,   
  ,        .
      link,     
   ,      ,    -
    ( ).
              
exit,         .   ,
   ,     -
,        ,   -
       .  
  ,          -
   ,  ,     -
 :           -
  ,      ,   
    ,       
 .
            -
     ,    ,    
       -
   . ,   , 
   .        
    .

    +--------------------------------------------------------+
    | 1.     - |
    |           . |
    | 2.   "" .             |
    | 3.  ,    ,|
    |       , -|
    |       8.                                   |
    | 4.   .                          |
    +--------------------------------------------------------+

     6.15.   ,    -
                    


     ,       UNIX,  
       ,   -
     ,     -
   ,    -   . -
      ,       
     ,     ,  
          ""
.      ,    -
         . 
    ,      
,        , 
 ,   ,  
     .
          6.16        .  
save_context         -

                                    157

    1.      ,    
  (  save_context)   0    
  .       ""  
(A),            (B)      
resume_context

    +------------------------------------------------------------+
    | if (save_context())  /*   |
    |                          */                        |
    | {                                                          |
    |     /*      */         |
    |     -                                                      |
    |     -                                                      |
    |     -                                                      |
    |     resume_context(new_process);                           |
    |     /*     ! */                     |
    | }                                                          |
    | /*      */  |
    +------------------------------------------------------------+

          6.16.   


   .     -
  B;   (A)   ,    
   . ,    
,      A ( , ,   
).     A      
    ,         A   
save_context,     0  0.    -
  A   save_context,     -
          resume_context. 
 ,  A    save_context   
0  (    )      
"    ".




     ,       -
            
.    ,      -
   ,   ,     -
    ;     
   .    -
  setjmp,     - longjmp (***). -
   setjmp      save_context,  -
        ,        ,    
save_context        ,        
setjmp           -
       .   
 ,

---------------------------------------
(***)           -
       ,         -
         (. [SVID 85]).     -
      .


                                    158

       setjmp,      
longjmp,         ,
  setjmp,  ,  1.



                  

          ,          
    -  ()  . -
,     ,    
,         -
 , ,      
           
   -     read.  
        , -
   .     ,    ,
     , ,    -
     ;       -
    ,  ,      -
,        (, -
,       ).    
       "  ",
     .

    +--------------------------------------------------------+
    | fubyte:                         #      |
    |                                 #    |
    |         prober   $3,$1,*4(ap)   #   ?      |
    |         beql     eret           #                   |
    |         movzbl   *4(ap),r0                             |
    |         ret                                            |
    | eret:                                                  |
    |         mnegl    $1,r0          #   (-1)  |
    |         ret                                            |
    +--------------------------------------------------------+

     6.17.           
                       VAX


      6.17      VAX  -
         -
.  prober ,     ,  ( -
    + 4),      ( 3),   ,
     eret,      -1  
   ;      .  
    ,     ,    -
  0      .  1  -
   (     fubyte).




           ,    -
           
      ,    
  ,       -
 . ,      -

                                    159

       ,      ,
     .       
    ;   ,  
 ,     .
        ,      
.  ,      :
  *    ,     -
      
  *    ( ,  ,   
     )
  *  
  *     
  *   () ,    
      :
    - 
    - 
    -      
    - ,   
  *  ,     ,   
     .

             :  , 
  ,  ,    -
  ,   ,       
   ,  ,   
        .  ,
  exec,      -
     ,   , 
   ,     ,    ,
     .     -
            -
 ,   (      -
  ),        -
     ( 9).




             -
       ,  ,  -
 -       -
      -    (  iget 
iput).  ,      ,    
 ,   .  ,   
      ,     , 
       ,      -
.




            (  allocreg,  6.18) 
    fork, exec  shmget ( 
).    ,     
       ,     -
.           -
    ,        -
,         (  ).
          

                                    160

( ,     exec),     allocreg  
         ,  
    .       
,        .  -
     ,    
         unlink,    
    7.5.   allocreg   
  .

    +------------------------------------------------------------+
    |  allocreg   /*    |
    |                         */                          |
    |  :  (1)                   |
    |                      (2)                         |
    |  :                 |
    | {                                                          |
    |         ;           |
    |      ;                                  |
    |       ;                   |
    |     (    )       |
    |               ;     |
    |         ;            |
    |     ( );                   |
    | }                                                          |
    +------------------------------------------------------------+

              6.18.   





             -
     fork, exec  shmat ( attachreg, 
6.19).          ,  
          .  
      ,      
   ,      , , -
     ,    ,  -
       .   
         -
  ,         -
      . ,   -
 -     8 -
,     1     7.5M 
.     ,    
,           , 
  ,       -
  .
      ,      attachreg   
   ,  .   
   - ,         growreg
(.   )      ;  -
      .  
,            -
,    . , , 
        0  (-
) ,   7  ( 6.20).   


                                    161

    +------------------------------------------------------------+
    |  attachreg  /*     */ |
    |  :  (1)    -   |
    |                           ()           |
    |                      (2) ,   |
    |                                                     |
    |                      (3)    ,|
    |                              -|
    |                                                       |
    |                      (4)                         |
    |  :      |
    |                                                    |
    | {                                                          |
    |            -  |
    |      ;                                                |
    |        :             |
    |              ;   |
    |            ;                           |
    |             ;             |
    |            |
    |       ;                                      |
    |          ;         |
    |           -|
    |      ;                                                   |
    |             |
    |      ;                                            |
    |      (      -|
    |      );                                               |
    | }                                                          |
    +------------------------------------------------------------+

              6.19.   


             
,       (0)   -
  (9 ).




            -
    sbrk.         -
  (          
)           .
        growreg (-
  6.21).     ,    
      -    -
            
-      .   
  growreg     ,  
    ;      , 
         -
    ,      -
.         growreg 
 :   sbrk       
      .    ( 
)  .        -


                                    162

                    
                 +---------+-------------+--------+
                 |    |  |  |
                 |  |   -|       |
                 |  |    |  |
                 |         |     |        |
                 +---------+-------------+--------+
       |         |      0      |    9   |
       +----+----+-------------+--------+
                +----+
                           v
                           +-------------+
                           |        |
                           +-------------+
                           |        |
                           +-------------+
                           |    846K     |
                           +-------------+
                           |    752K     |
                           +-------------+
                           |    341K     |
                           +-------------+
                           |    484K     |
                           +-------------+
                           |    976K     |
                           +-------------+
                           |    342K     |
                           +-------------+
                           |    779K     |
                           +-------------+

     6.20.     

   .       .
       ,     
(   )      
 ,       .  -
           -
    growreg;       ,   
     (.  9).   -
  ,    ,      -
.           
         
   (,      -
 ).
    , ,       -
  128    6          -
    1  (1 ).       
    -
  134  135 - 1   - ,   -
    ,     .    
 ,          -
 .       6.22.




      ,      ,  


                                    163

    +------------------------------------------------------------+
    |  growreg  /*    */          |
    |  :  (1)      |
    |                                     |
    |                      (2) ,    -  |
    |                             (    |
    |                           ,   -  |
    |                          )                          |
    |  :                            |
    | {                                                          |
    |      (  )                    |
    |     {                                                      |
    |            ;      |
    |           ();         |
    |         (      |
    |          )                                      |
    |        {                                                   |
    |              ;                 |
    |                 |
    |                ;               |
    |        }                                                   |
    |     }                                                      |
    |           /*    */ |
    |     {                                                      |
    |          ;                       |
    |          ;                 |
    |     }                                                      |
    |                                                            |
    |             |
    |       ;                               |
    |           - |
    |      ;                                                  |
    | }                                                          |
    +------------------------------------------------------------+

           6.21.    


""         -
 exec,         
  (.  9).        -
,       ,  
      .     
     ,     -
 ,    ""    ( -
 6.20).    , ,   -
   (memory  fault)        
     (  ).  
     (       
 0)        
  .       
, ,       ,    
    ,      
 .
            loadreg ( 6.23) 
   ,       -
,      ,      , 
       .    


                                    164

                     
                                         
     +-------+----------+------+       +-------+----------+------+
     |  | -| - |       |  | -| - |
     | -|  |   |       | -|  |   |
     |     |  - |     |       |     |  - |     |
     | - |   | -|       | - |   | -|
     |    |  |    |       |    |  |    |
     +-------+----------+------+       +-------+----------+------+
     |       |          |      |       |       |          |      |
     +-------+----------+------+       +-------+----------+------+
     |       |          |      |       |       |          |      |
+-------+----------+------+  +-------+----------+------+
|       |   128K   |  6K  |  |       |   128K   |  7K  |
  +---+---+----------+------+    +---+---+----------+------+
    +--+                         +--+
            v                                 v
            +-------------+                   +-------------+
            |    342K     |                   |    342K     |
            +-------------+                   +-------------+
            |    779K     |                   |    779K     |
            +-------------+                   +-------------+
            |    846K     |                   |    846K     |
            +-------------+                   +-------------+
            |    752K     |                   |    752K     |
            +-------------+                   +-------------+
            |    341K     |                   |    341K     |
            +-------------+                   +-------------+
            |    484K     |                   |    484K     |
            +-------------+              +-------------+
            |             |        -->|    976K     |
            +-------------+                   +-------------+
            |             |                   |             |
            +-------------+                   +-------------+
            |             |                   |             |
            +-------------+                   +-------------+
                            

           6.22.     1 


    "  ",     
             
  read.
        ,    -
  ,   ,    
  ,      ,    -
   -
       .   ,     
    ,   ,      
   exec       9.    -
,              ,
     .    
loadreg       ,    
 ,     (",   ").
    ,  ,       7K  -
,       0,    -
   1     ( 6.24).    


                                    165

    +------------------------------------------------------------+
    |  loadreg    /*      */   |
    |  :  (1)      |
    |                                     |
    |                      (2)           |
    |                      (3)              |
    |                      (4)      -|
    |                                            |
    |                      (5)      |
    |  :                            |
    | {                                                          |
    |          (|
    |     growreg);                                              |
    |        "  ";     |
    |       ;                             |
    |           |
    |       :                                       |
    |          ,     -|
    |           ;                                  |
    |              ;        |
    |          ,   ,  ;      |
    |        (  -  |
    |      read);                                           |
    |     ;                                  |
    |        "   -|
    |     ";                                                 |
    |       ,  -|
    |       ;                                  |
    | }                                                          |
    +------------------------------------------------------------+

        6.23.      


            
  0    allocreg  attachreg.    -
  loadreg,         growreg  
  -  -,        1 , 
-,       -    growreg
     .     
         :
 7 ,   ,         
  (  ),      -
   1K.

                     
                                         
     +-------+----------+------+       +-------+----------+------+
     |  | -| - |       |  | -| - |
     | -|  |   |       | -|  |   |
     |     |  - |     |       |     |  - |     |
     | - |   | -|       | - |   | -|
     |    |  |    |       |    |  |    |
     +-------+----------+------+       +-------+----------+------+
|  ---  |          |   0  |       |       |     0    |   8  |
     +-------+----------+------+       +---+---+----------+------+
     ()    -           +--+
                                 |
                                              v

                                    166



                                              +-------------+
                                              |        |
                        +-------------+
                                      |    779K     |
     +-------+----------+------+              +-------------+
     |  | -| - |              |    846K     |
     | -|  |   |              +-------------+
     |     |  - |     |              |    752K     |
     | - |   | -|              +-------------+
     |    |  |    |              |    341K     |
     +-------+----------+------+              +-------------+
     |       |     0    |   1  |              |    484K     |
     +---+---+----------+------+              +-------------+
         +--+                                 |    976K     |
            |                                 +-------------+
            v                                 |    794K     |
            +-------------+                   +-------------+
            |        |                   |             |
            +-------------+                   +-------------+
     () ,          ()   -
            -             growreg
          ( 
          
         growreg)


          6.24.    ()




    +------------------------------------------------------------+
    |  freereg      /*    */|
    |  :    () |
    |  :                            |
    | {                                                          |
    |     (      -  |
    |     )                                                   |
    |    {                                                       |
    |       /*        */|
    |          ;                          |
    |        (   )              |
    |               ;                     |
    |        ;                               |
    |    }                                                       |
    |     (   )                 |
    |           ( iput);                 |
    |         ;      |
    |         ;|
    |      ;                                  |
    |         ;           |
    |       ;                             |
    | }                                                          |
    +------------------------------------------------------------+


             6.25.   

                                    167


            ,      
          ( 6.25).
    ,         -
 iput,      ,   -
  allocreg.         -
,            .
, ,      ,  
  6.22.          , 
 7       .

    +------------------------------------------------------------+
    |  detachreg   /*     */ |
    |  :           |
    |                                     |
    |  :                            |
    | {                                                          |
    |        ,  |
    |        ,                      |
    |            ,    ;  |
    |      ;                              |
    |         ;          |
    |     (       -|
    |        )                     |
    |           ( freereg);             |
    |         /*      |
    |                             0,    - |
    |                               */   |
    |    {                                                       |
    |             (  - |
    |          );                                          |
    |            ;                        |
    |    }                                                       |
    | }                                                          |
    +------------------------------------------------------------+

             6.26.   




           exec,  exit  
shmdt (  ).     -
          ,  -
                (
detachreg,   6.26).      
   ,     (     freereg).  
         , 
     ,     -
.      0      
     (      
      ,      
     7.5),      freereg.  -
          ,  
  ,       
 (.  7.5),          -
.



                                    168

              
          +--------------+               +-------------+
   |              +-------------->|  |
          +--------------+      +------->+-------------+
    |              +----+ |
          +--------------+    | |        +-------------+
      |              +--+ +-|------->|      +-+
          +--------------+  |   |        +-------------+ | -
              A      |   |                        | -
                            |   |        +-------------+ | 
                            +---|------->|      +-|-+ -
          +--------------+      |        +-------------+ | | 
   |              +------+                        | |
          +--------------+               +-------------+ | |
    |              +-------------->|      |<+ |
          +--------------+               +-------------+   |
      |              +------+                          |
          +--------------+      |        +-------------+   |
              B          +------->|      |<--+
                                         +-------------+

         6.27.   

    +------------------------------------------------------------+
    |  dupreg   /*     |
    |                       */                            |
    |  :        -|
    |                                                      |
    |  :   ,  - |
    |                                |
    | {                                                          |
    |      ( )                             |
    |          /*       -   |
    |               ,    -  |
    |               attachreg */                      |
    |           (   );       |
    |        ( allocreg);            |
    |         |
    |            -|
    |         ;                        |
    |          ;    |
    |     ""      -|
    |        ;                                      |
    |      (   );          |
    | }                                                          |
    +------------------------------------------------------------+

     6.28.     




      fork ,     -
 .     (    -
  ),       ; 
        ,    -
       .  -
           -
,         ,    

                                    169

     .     -
   6.27,   A     fork 
B     .    A -
 ,   B     
  A.        
   (  ),      B  
      .     -
         , 
    ( 9).   6.28   -
   (dupreg).




                 
  ,        -
      "   "  -
      ,   , -
    " ".    -
 ,        "-
   "   "  "     -
      "  "      
.

                                 +-------------------------------+
                                 |      2  |
                                 |     -   |
                                 |              |
                                 |                               |
                                 |     -  |
                                 |       |
                                 |                        |
      -+-------------------------------+
              ^                  |      1  |
              |                  |      -  |
              |                  |                  |
              |                  |                               |
              |                  |     -  |
              |                  |         |
              |                  |                         |
      ------+-------------------------------+
              ^
              |
              |
      

     6.29.    -
                   


           -
   :          (
  1),     ,  -
   .     ,  -
           
   2 ( 6.29).   -
        ,     
      ,    -
;     ,      -

                                    170

.




         ,     -
   ,    ""  -
   "  " (      -
).       ,     -
         -
  (). ,     ,    
,          -

     a ---+    +---   ---+
                 |    |       -        |
     b -++|----+                           |
               |||                                +----  A
     c -|++--------       |
               +----++--- ()  --+
     d --+   ||+--+|
                |   |||+--+
     e --|---|+||
                |+--|-+|
     f --|+  +--|--   ---------  B
                | +----|-() 
     g --|-+    |
               +|------+
     h -++---------    - ------  C
                                  

     6.30. ,    -
                  ,      


       .   
,        ,  
    .  ,  -
  . -,     -
,    ,     ,  
""     "  ".  -
      ,    ,  
,              
             
     (         
  2   3).   6.30   , -
    .
         ,           
  .   6.30, ,  "-
 "  " -"     ("-
  A").  -   ,   
 ,      ,   -
 .  ,   -,  -
   ,  ,    -
,  ,     .  -
    ,        -
.        
  ,         -
       ,     
     ,     

                                    171

 . ,   ,   
   ,     .

    +------------------------------------------------------------+
    |  sleep                                             |
    |  :  (1)                   |
    |                      (2)                          |
    |  : 1,     -|
    |                      ,    ;    |
    |                        longjump,  |
    |                        ,  |
    |                        ;                   |
    |                      0 -    ;        |
    | {                                                          |
    |         , |
    |       ;                          |
    |        ;              |
    |       -  - |
    |     ,    ;              |
    |         ;        |
    |        ;                 |
    |     (    )      |
    |    {                                                       |
    |         ;                    |
    |       /*      ,    |
    |           "" */                           |
    |           ,   |
    |          (    -  |
    |        );                                             |
    |        (0);                                      |
    |    }                                                       |
    |                                                            |
    |    /*    ,   |
    |        */                                         |
    |     (        )|
    |    {                                                       |
    |         ;                    |
    |       /*      ,    |
    |           "" */                           |
    |        (        -|
    |        )                                                |
    |       {                                                    |
    |               ,  |
    |                  ;     |
    |            (0);                                  |
    |       }                                                    |
    |    }                                                       |
    |       -  - |
    |     ,      ;                    |
    |                                                            |
    |        ,  |
    |         ;                     |
    |     (       |
    |      )                                     |
    |        (1);                                      |
    |      longjump;                            |
    | }                                                          |
    +------------------------------------------------------------+
              6.31.   

                                    172






      6.31    .   -
     ,    ,
   (  )       
  ,     ,  -
 ,     .   -
 "",       -
 ,     -   -
.     (    ) 
     "".    -
  "",     : -
     sleep ,  -
    (       -
)    .

    +------------------------------------------------------------+
    |  wakeup   /*   -  |
    |                       */                              |
    |  :                        |
    |  :                            |
    | {                                                          |
    |         , -|
    |        ;                       |
    |     -    |
    |      ;                                   |
    |     ( ,     |
    |     )                                                |
    |    {                                                       |
    |          -;                      |
    |          ,     -|
    |         "  ";                        |
    |           ,   -|
    |         (  );                    |
    |        ,   ,  |
    |         ;                                  |
    |        (    )                  |
    |                (-|
    |              );                                  |
    |                                            |
    |        (     -  |
    |        ,   )                   |
    |                - |
    |             ;                                            |
    |    }                                                       |
    |        ;|
    | }                                                          |
    +------------------------------------------------------------+

     6.32.    


        ,  
  wakeup ( 6.32),       
    ,     -
 .  iput, ,    

                                    173

     ,   . 
             
,   -.   wakeup  -
    ,   . -
   ,    , -
    :    ,   -
,  ,     ;      -
       ,   ;
    ,     ,  .
          ,   
,        (-
 ,        -
);    ,       -
,   ,     -
 ,   ,          
      ( 8). ,  -
    .        
    : "" (wakeup)   
  ;    "",    
   .
    ,    ,     -
 sleep  wakeup,  ,   -
        .    
   ,  "" , ,
    (  )    -
 -,   .      
   ,      
   .   ,    -
      ,      
,           
     .      
    ""   ,   .
        ;      
,    ()   
        .
    ,         ,
          ,  -
           ( 10).   ,
,  ,      , 
      ,     
   .      -
  (   ),     -
   :      
      .  ,   
   ,     .  
           
 ()    ,   -
          -
.
      -     ,  -
    (    )  -
       sleep. 
    sleep   "",   -
       . 
    ,     -
     ,      -
 .      ,  
     (****).


                                    174

---------------------------------------
(****)    ""    ""    " " 
       " ".          
       ,          
       .

     ,            sleep,
  ,    . ,  -
     sleep   , -
      wakeup.   -
   ,    ,
       ,       -
.            , 
,              -
  .
        ""     (     
  -  ),     
longjump (   ,     ). 
   longjump     ,
      . , 
 ,    ,     
,  read   ,    . 
   ,       -
.          -
,      .   
         ,    
setjump         
longjump.
      ,   ,    
 ,     longjump.     -
  sleep      "",  -
  longjump     sleep    ,
 1.         
  setjump     sleep    
longjump     .   -
    ,         .
 , ,       
  ,  ;      
 ,    ,   -
    longjump,    .    
,     longjump;   
     ,    , 
          -
.




           .    UNIX
         
       ,   -
          -
 .           
  .      -
, ,      ,   
    (   ,  -
   ,     -
)    (       -
    ),      -

                                    175

         , 
      .    -
      ,   
        -
    .      ,
       -
 ,        -
 .         
.         -
 (sleep)   (wakeup) .   , -
   ,         -
         -
,        .




  1.       ,  
               
      .
  2.     AT&T 3B2  NSC  32000   
          ( ).   
          ,    -
             -
         .      
           ,     -
        .     -
             .
  3.    VAX-11     
     ,       -
     .     ,     -
     ,   :      . -
             - ,    - 
      ,       ,    
          ?    -
       VAX-11      . 
           ?   11   
      :        -
      VAX-11 ?
  4.             
     .     ,   -
          ?
  5.    MC68451      
     Motorola  68000          256
       16 .  ()    
       32  .    -
         .     -
       ?
  6.    ,     
     6.5.  ,        (   
     )         (
        ).   -    -
          68432,       -
        ,       
       ,       () ?  
             
     ,         ,    -
     ,    ?
 *7.   ,       -

                                    176

       .        -
     .
  8.  ,    ,    ,
                , 
        ?
  9.     . ,     
           .  ,  
            .  ,
        .
 10.  ,     ,     ,
       .  ,     
       ?
 11. ,  ,    ,  -
                  
         . ,    
           2.
 12.         ,    ,
          ,    -
       .          
          . ,  
      (  )       
      2.
 13.     read   
     read(fd,buf,1024);
           . ,   
      read      ,     -
              
       ,   buf,  ,
            .      
     ,     .   
          ?  ,  -
            
      ?
 14.      ,          
          ( 6.17) ,  -
         ?
*15.    sleep  wakeup    
      ,    ,  . 
         ,     -
        ? (:      -
           ).
*16.  ,       -
      A, ,   sleep,    ; -
     ,            -
          ,   -
       A.      ?    
       ?  ,        -
      ?
 17.   ,     wakeup   ,
        A,   ,      -
          ?
 18.       ,   -
            - ,  
        .     -
         . ,  -
             wakeup  ,   
         ,       ,
        .
 19.       sleep    wakeup   Multics

                                    177

       :
     sleep ();
     wakeup (, );
      ,   wakeup   -
      .         -























































                                    178

Last-modified: Sun, 20 Jun 2004 10:24:20 GMT
: