Page 420 - DCAP103_Principle of operating system
P. 420

Unit 14: Case Study of Linux Operating System



            The task structure contains a variety of fields. Some of these fields contain pointers to other data   Notes
            structures or segments, such as those containing information about open files. Some of these
            segments are related to the user-level structure of the process which is not of interest when
            the user process in not runnable. Therefore, these may be swapped or paged out, in order not
            to waste memory on information that is not needed. For example, although it is possible for a
            process to be sent a signal while it is swapped out, it is not possible for it to read a file. For this
            reason, information about signals must be in memory all the time, even when the process is not
            present in memory. On the other hand, information about file descriptors can be kept in the user
            structure and brought in only when the process is in memory and runnable. The information
            in the process descriptor falls into the following broad categories:
               1.  Scheduling Parameters: Process priority, amount of CPU time consumed recently, amount
                 of time spent sleeping recently. Together, these are used to determine which process to
                 run next.

               2.  Memory Image: Pointers to the text, data, and stack segments, or page tables. If the text
                 segment is shared, the text pointer points to the shared text table. When the process is
                 not in memory, information about how to find its parts on disk is here too.
               3.  Signals: Masks showing which signals are being ignored, which are being caught, which
                 are being temporarily blocked, and which are in the process of being delivered.

               4.  Machine Registers: When a trap to the kernel occurs, the machine registers (including
                 the floating-point ones, if used) are saved here.

               5.  System Call State: Information about the current system call, including the parameters,
                 and results.
               6.  File Descriptor Table: When a system call involving a file descriptor is invoked, the file
                 descriptor is used as an index into this table to locate the in-core data structure (i-node)
                 corresponding to this file.
               7.  Accounting: Pointer to a table that keeps track of the user and system CPU time used by
                 the process. Some systems also maintain limits here on the amount of CPU time a process
                 may use, the maximum size of its stack, the number of page frames it may consume, and
                 other items.

               8.  Kernel Stack: A fixed stack for use by the kernel part of the process.
               9.  Miscellaneous: Current process state, event being waited for, if any, time until alarm clock
                 goes off, PID, PID of the parent process, and user and group identification.
            Keeping this information in mind, it is now easy to explain how processes are created in Linux.
            The mechanism for creating a new process is actually fairly straightforward. A new process
            descriptor and user area are created for the child process and filled in largely from the parent.
            The child is given a PID, its memory map is set up, and it is given shared access to its parent’s
            files. Then its registers are set up and it is ready to run.

            When a fork system call is executed, the calling process traps to the kernel and creates a task
            structure and few other accompanying data structures, such as the kernel mode stack and a
            thread_ info structure. This structure is allocated at a fixed offset from the process’ end-of-stack,
            and contains few process parameters, along with the address of the process descriptor. By storing
            the process descriptor’s address at a fixed location, Linux needs only few efficient operations to
            locate the task structure for a running process. The majority of the process descriptor contents
            are filled out based on the parent’s descriptor values. Linux then looks for an available PID,
            and updates the PID hash table entry to point to the new task structure. In case of collisions
            in the hash table, process descriptors may be chained. It also sets the fields in thetask_ struct
            to point to the corresponding previous/next process on the task array. In principle, it should


                                             LOVELY PROFESSIONAL UNIVERSITY                                   413
   415   416   417   418   419   420   421   422   423   424   425