Unix process implementation Finding parts of a process using by zwj23860

VIEWS: 17 PAGES: 4

									                                                                        Finding parts of a process using process
           Unix process implementation                                  structure
                




                   When a user thread traps to kernel, it
                   starts running with different memory
                   map, kernel mode PC, and kernel mode
                   stack.
                




                   Two structures are maintained by the
                   kernel
                    ¡




                        Process table
                    ¡




                        User structure



6/4/2001                                                         1   6/4/2001                                                     2




        Process table (always memory-resident)                                  User structure
    ¢




           Scheduling parameters                                                ¢




                                                                                    Contains info that is not needed when
           ¡




                   Process priority, CPU time consumed                              the process is not in memory (can be
                   recently, recent sleep time                                      swapped out)
    ¢




           Memory image                                                             ¡




                                                                                        Signal info should be in process table,
           ¡




                   Pointers to the text, data, stack segments,                          since signals may be received when the
                   their page tables
                                                                                        process is swapped out.
    ¢




           Signals                                                              ¢




                                                                                    Machine registers
           ¡




                   Which are ignored, which are temporarily
                   blocked, etc.
                                                                                    ¡




                                                                                        Saved when trap to kernel occurs
    ¢




           Others
                                                                                ¢




                                                                                    Current system call state
                   Process state, events being waited for,                              Parameters, results
                                                                                    ¡

           ¡




                   PID, parent’s PID, user ID.
6/4/2001                                                         3   6/4/2001                                                     4




                                                                                                                                      1
           Continued …
                                                                               Process creation (fork)
            




               Open file descriptor table                               




                                                                           Look for a free slot in process table
                   Maps to the in-core inode table
               ¡




                                                                                   Copy parent’s entry to child’s entry
                                                                               ¡




            




               Account info                                             




                                                                           Allocate memory
                   Points to a table that keeps track of user
               ¡




                                                                                   Copy data and stack segments from parent
                                                                               ¡




                   and system CPU time used
                                                                                   Copy user structure from parent
                                                                               ¡




            




               Kernel stack
               ¡




                   A fixed stack for use by the kernel part
                                                                        




                                                                           Text segment may be shared
                   of the process




6/4/2001                                                        5   6/4/2001                                                  6




           Copy on write                                                       Shared memory
                                                                           £




                                                                                shmid = shmget ( size, …)
                                                  Page table               £




                                                                                addr = shmat ( shmid, shmaddr, …) (attach)
                                                  of receiver
       Page table                                                                  shmaddr is a suggested address (or 0)
                                                                                   ¤




       of sender 3                           2                             ¥




                                                                                shmdt ( shmid ) (detach)
                              1

                                                                                       Mem map                   Mem map
                                   ¢




                                  Copy-
                                  on-write
                                                                                                    Shared
                              (read-only                                               Process A    region
                             protection fault)                                                                   Process B

6/4/2001                                                        7   6/4/2001                                                  8




                                                                                                                                  2
                                                                 Example: ls command
           Processing shell commands




                                                               Steps in executing the command ls type to the shell
6/4/2001                                                9     6/4/2001                                            10




                                                                    Shared mapped files
           New address space
            




               System V, BSD, support mapped files                       Two processes can share a mapped file.
            




               New page table indicates no in-core
               pages
            




               The new process immediately gets
               page fault (only required pages are
               brought in from the executable file on
               disk)




                                                             A new file mapped simultaneously into two processes
6/4/2001                                                11    6/4/2001                                            12




                                                                                                                       3
           Threads in Unix
                                                                                           Unix scheduler
      




           Kernel threads supported in some versions,
           e.g., System V, Solaris
                                                                                           £




                                                                                               Multi-level queues based on priority
      




           How to maintain traditional Unix semantics?                                         recalculated once a second
      




           E.g., a thread in a process forks
                                                                                           £




                                                                                               Priority = cpuUsage + nice + base
                                                                                                   cpuUsage=weighted average # of clock
                                                                                               ¤




                   Should child process have copies of all
               ¡




                   threads?                                                                        ticks/sec the process has had while
                                                                                                   running during past few seconds
                   If so, what if one of them was blocked reading
               ¡




                                                                                                                                      ¥




                                                                                                   cpuUsage=(new + old_cpuUsage)/2
                                                                                               ¤




                   keyboard? Should the copy be also blocked?
                                                                                                   only recent usage counts
                    ¢




                        If so, which should get the next keyboard input?
                    ¢




                        If not, what should the new copy be doing?
                                                                                               ¦




                                                                                                   -20 <= nice <= 20 (user can choose only
                                                                                                   non-negative values)

6/4/2001                                                                   13   6/4/2001                                                     14




                                                                                    Multi-level Q structure
           Priority calculation
           §




                   base differentiates different classes of
                   processes (hard-wired in OS)
           §




                   E.g., a process that has just read a
                   block from disk should get next time
                   slice soon to keep the disk busy
           §




                   When the priority (rounded to an
                   integer) changes, the process is moved
                   to the corresponding Q in the next slide



6/4/2001                                                                   15   6/4/2001                                                     16




                                                                                                                                                  4

								
To top