Docstoc

proc_ds

Document Sample
proc_ds Powered By Docstoc
					           Computer Science 454

                          Processes In Xinu




              Process vs. Program
•   process                              – Requires resources to be
     – dynamic                              allocates by the OS.
     – part of a program in              – zero or more processes
        execution.                          may executing the same
     – a live entity, it can be             code.
        created, executed, and      •   program
        terminated.                      – static
     – it goes trough different          – no states
        states
          • wait
          • running
          • ready, etc.




                                                                      1
       Process creation, system calls and
              Context Switching
•   getpid() /*gets the current pid*/     •   Context Switch
•   getppid() /*gets the parent                – Saves current machine
    pid*/                                        state
•   exec, execl, execv /*See the               – loads the next scheduled
    man page!*/                                  process
•   execl(“/bin/ls”, “ls”, “-l”, (char         – via interrupt,
    *0)); /*overlay original program             multiprogramming, etc.
•   use fork then exec() - how
    shell commands work
•   orphaned/zombie processes
    (later)
•   XINU implements fork() as
    create() -(see man fork)




          Parent & child processes
main()
{
  int pid;             /*hold process-id in parent*/
  printf(“Just one process so far\n”);
  printf(“Calling fork …\n”);
  pid = fork(); /* create new process */
  if ( pid == 0 )
          printf( “I am the child\n”);
  else if ( pid > 0 )
          printf( “I’m the parent, the child has pid: %d\n”, pid);
  else
          printf( “fork returned error code, no child\n”);
}




                                                                            2
                        fork() example:
     printf(“one\n”);     PC
     pid = fork();
     printf(“two\n”);

    A                                            Before

                                                 After

     printf(“one\n”);                    printf(“one\n”);
     pid = fork();                       pid = fork();
     printf(“two\n”);     PC             printf(“two\n”);    PC
    A
                                        B




    List and Queue manipulation
•   Important Constants:            •   List and Queue Processing
     – NSEM # of semaphores              – Doubly linked lists
     – NQENT # of entries in q                • head
       array (see q.h on page 58)             • tail
     – NPROC Max # of                         • node:
       processes a system can                      – prevPtr
       have.
                                                   – data
                                                   – nextPtr




                                                                    3
                    Queue Structure:
      head                                                             tail
                 next                             next
 ^      MININT
                                prev
                                       KEY
                                                               prev
                                                                       MAXINT
                                                                                   ^

* Highest priority items at link next to tail. (see page 62 in text)
* This is an array implementation of a doubly linked list
* enqueue, dequeue (see page 60 in text)




  Implementation of Queue Array
 • Used to keep track of:
      – Ready List
                                                 Pid     key   next     prev
         • 2 entries                         0
                                             1
      – List for each Semaphore              *                                    NPROC
                                             *
         • 2*NSEM                            *
                                             NPROC -1
                                             NPROC
      – Sleep List                           *
                                             *                                  2+2+2(NSEM)
         • 2 entries                         *
                                             NQENT

 • See page 57 in text
 •   4+2*NSEM + NPROC = NQENT




                                                                                              4

				
DOCUMENT INFO