Page 428 - DCAP103_Principle of operating system
P. 428

Unit 14: Case Study of Linux Operating System



                                                                                                  Notes
                   Figure 14.11: The Sequence of Processes Used to Boot Some Linux Systems

                            Process 0







                                                       Page
                             Process 1                       Process 2
                                       init           daemon



                         Terminal 0            Terminal 1                Terminal 2
                getty   Login :       login    Password :       sh      %cpf1f2




                                                                cp

            In the Figure 14.11, the getty process running for terminal 0 is still waiting for input. On terminal
            1, a user has typed a login name, so getty has overwritten itself with login, which is asking for
            the password. A successful login has already occurredon terminal 2, causing the shell to type the
            prompt (%). The user then typed cp f1 f2 which has caused the shell to fork off a child process and
            have that process exec the cp program. The shell is blocked, waiting for the child to terminate, at
            which time the shell will type another prompt and read from the keyboard. If the user at terminal
            2 had typed cc instead of cp, the main program of the C compiler would have been started, which
            in turn would have forked off more processes to run the various compilers passes.
            14.4 Memory Management in Linux

            The Linux memory model is straightforward to make programs portable and to make it possible
            to implement Linux on machines with widely differing memory management units, ranging
            from essentially nothing (e.g., the original IBM PC) to sophisticated paging hardware. This is
            an area of the design that has been barely changed in decades. It has worked well so it has not
            needed much revision. We will now examine the model and how it is implemented.
            14.4.1 Fundamental Concepts of Memory Management in Linux
            Every  Linux  process  has  an  address  space  logically  consisting  of  three  segments:  text,  data,
            and stack. An example process’ address space is depicted in Figure 14.12 as process A. The text
            segment contains the machine instructions that form the program’s executable code. It is produced
            by the compiler and assembler by translating the C, C++, or other program into machine code.
            The text segment is normally read-only. Self-modifying programs went out of style in about
            1950 because they were too difficult to understand and debug. Thus the text segment neither
            grows nor shrinks nor changes in any other way. The data segment contains storage for all the
            program’s variables, strings, arrays, and other data. It has two parts, the initialized data and the
            uninitialized data. For historical reasons, the latter is known as the BSS (historically called Block
            Started by Symbol). The initialized part of the data segment contains variables and compiler
            constants that need an initial value when the program is started. For example, in C it is possible
            to declare a character string and initialize it at the same time. When the program starts up, it
            expects that the string has its initial value. To implement this construction, the compiler assigns
            the string a location in the address space, and ensures that when the program is started up, this
            location contains the proper string. From the operating system’s point of view, initialized data
            are not all that different from program text both contain bit patterns produced by the compiler
            that must be loaded into memory when the program starts.


                                             LOVELY PROFESSIONAL UNIVERSITY                                   421
   423   424   425   426   427   428   429   430   431   432   433