Unformatted text preview:

newproca Process Creation Conceptually simple The Tempo 32 Operating System Part 6 System Call Implementation Processes and Timers validate parameters allocate an unused process table entry fill in the appropriate values allocate user and kernel stack space initialize stacks for initial return from kernel The most complicated part of process creation is getting the initial user and kernel stack contents correct 1 2 newproca pseudocode 1 newproca pseudocode 2 Find an unused process table entry if not found return error PROCTBLFULL Extract system call arguments Setup tag priority and process ID Allocate user mode stack handle errors Determine size of string arguments Set user stack info args ptr to args return address processDone Copy string arguments and pointers to usermode stack Allocate kernel mode stack always 1 page Initialize kernel stack user mode stack segment and stack pointer eflags register code segment and instruction pointer remaining segment and general purpose registers Initialize event queues empty unmasked Setup file descriptors 0 1 for keyboard display 3 newproca pseudocode 3 4 User Stack at Process Startup Mark all other file descriptors as available for use Mark process as not signaled see signal discussion for details Increase number of processes in the system Add process to appropriate ready queue by calling addready If new process has priority greater than current creating process add current process to the appropriate ready queue and set rs to 1 Return the ID of the new process String N String 2 Bottom of stack String 1 Null Ptr Addr Str N Addr Str 2 Addr Str 1 Addr Array Initial stack pointer N processDone 5 6 1 Kernel Stack at Process Startup User Stack Sel User Stack Ptr eflags Reg User Code Sel Instr Pointer Other Segment Registers 4 Bottom of the kernel stack Popped restored by the iret instruction after isr30z in kernel s Initial kernel stack pointer Gen Purpose Registers 8 addready The addready function has a single parameter a pointer to a process table entry The state member of that process table entry is set to PROCESS READY The process table entry is linked using the next and prev members onto the appropriate ready queue 7 8 getpid pseudocode getpstate pseudocode Getpid almost warrants no explanation since it only extracts and returns the pid member of the process table entry for the current process The only thing worth noting is that it is always assumed that the global variable activeProcess points to the process table entry for the running process Getpstate like getpid just returns the contents of a member in this case state of the process table entry For this call we must map from the pid to a pointer to the process table entry This is done by the pid2a function in sys c which just does a linear search of the entire array returning the appropriate pointer if the pid was found or NULL 0 otherwise Once the pointer is located or not the appropriate value is returned to the caller 9 10 getprio getquantum setquantum setprio psuedocode Each of these system calls just return a field from the process table for the currently running process or get set the value of a global variable No further explanation should be necessary to understand their implementation Verify argument is within allowed range for process priorities if not return error If the new priority is the same as the current priority return without change Modify the process table entry If there now exists a ready process with a priority higher than the current process priority 11 Move the current process to the ready state by calling addready Set rs to 1 to force a context switch Return 12 2 yield pseudocode exit pseudocode Recall that the yield system call causes the running process to voluntarily relinquish the CPU to another process at the same priority The steps taken are Exit does little direct work add the current process the one yielding the CPU to the appropriate ready queue by calling addready set rs to 1 to force a context switch return 13 The exitstatus member of the process table entry of the terminating process is set to the value of the argument to exit this value can be retrieved by a waiting process that called waitproc Set rs to 2 so the process will be terminated see the code at xterm in kernel s and xcleanup in sys c discussed later Return but since rs is 2 control never makes it back to the process 14 Return from a root function waitpid waitproc pseudocode 1 If the root function of a process should attempt to return the instruction pointer will be set to the value that was at the top of the stack when the root function began execution Since that is processDone it will be executed All processDone does is call exit with the value that was returned by the root function left in the eax register Extract arguments if the process specified does not currently exist return NOSUCHPROCESS If timeout is 0 return TIMEOUT why If timeout is INFINITE set process state to PROCESS WAIT Otherwise set process state to PROCESS TIMED WAIT and enqueue on the delta queue discussed elsewhere Invoke block process will awaken when the specified process exits see xcleanup or the timeout interval expires 15 16 waitpid waitproc pseudocode 2 Aside Variable Return Reasons When awakened after blocking check the timedOut member of the process table entry As just seen a system call may return a variety of different status values Some of these are obvious and result from argument errors In other cases the status to be returned depends on why a process is awakened after being blocked Since the awakened process may not run immediately after being made ready the reason for the awakening is stored in its process table entry For example this is the function of of the timedOut member of the process table entry If set return TIMEOUT Otherwise store the exit status from the terminated process in the location specified by the argument and return NOERROR 17 18 3 kill pseudocode 1 kill pseudocode 2 If a process is trying to kill itself just call exit If the process being terminated does not exist return NOSUCHPROCESS Remove the process from any queues on which it may reside in some cases a process may be on multiple queues Reclaim nodes used for unread messages Free pages of memory occupied by the user and kernel stacks Mark the process table entry unused Linearly search the process table for any processes waiting for termination of the process being killed If any are found mark the exit status as PROCESS KILLED


View Full Document

UNO CSCI 8530 - System Call Implementation

Loading Unlocking...
Login

Join to view System Call Implementation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view System Call Implementation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?