>
This module contains functions that manage the different aspects related to processes.
Function Number | Function Name | Arguments | Return Value |
---|---|---|---|
GET_PCB_ENTRY = 1 | Get Pcb Entry | NIL | Index of Free PCB. |
FREE_USER_AREA_PAGE = 2 | Free User Area Page | PID | NIL |
EXIT_PROCESS = 3 | Exit Process | PID | NIL |
FREE_PAGE_TABLE = 4 | Free Page Table | PID | NIL |
KILL_ALL = 5 | Kill All | PID | NIL |
loop through the Process Table{ if ( process table entry is free ) Set the PID to index of the entry Set the STATE to (ALLOCATED, - ) Set PTBR to PAGE_TABLE_BASE + 20*index /* See Memory Organisation */ Set PTLR to 10. /* Address space of processes in eXpOS has 10 pages */ return index; } return -1;Called by Fork system call.
/* If the user are page is swapped out, it has to be swapped back first. */ Get the User Area Page number from the process table entry corresponding to the PID; loop through the Resource Table{ if ( the resource table entry is valid ) if (the resource is a file) Close the corresponding file by calling the Close() function in the File Manager Module. if (the resource is a semaphore) Release the semaphore by calling the Release Semaphore() function in the Resource Manager Module. Invalidate the resource table entry. } Free the User Area page by calling the release_page() function in the Memory Manager module; return; Note: The user area page holding the return address for the call to free_user_area_page() has been released! Neverthless the return address and the saved context of the calling process will not be lost. This is because release_page() is non blocking and hence the page will never be allocated to another process before control transfers back to the caller. The calling function gets "time" to either invoke the scheduler using the same stack page or to reallocate the same page again for a different purpose.Called by the exit_process function.
if (the current process is not in the exec system call) // check MODE_FLAG { loop though the process table entries { /* Wake up all processes waiting for the current process */ if( process is waitng for the current process ) /* indicated by the STATE = (WAIT_PROCESS, PID ) */ Set STATE of the process to (READY, - ) /* Set the children of the process as Orphan */ if( process has PPID as that of the current process) Set PPID to -1. } } Free the Page Table entry corresponding to the process by invoking the Free_Page_Table() function; Free the User Area Page corresponding to the process by calling the Free_User_Area_Page() function; /* After the User Area Page has been deallocated, the process is executing without a kernel stack. Hence the process should immmediately be scehduled out */ Set the state of process as (TERMINATED , - ) return; /* Note that the return statement is executing using a deallocated stack page. See note after free_user_area_page() */Called by exec system call, exit system call, exception handler, shutdown and logout.
1. Why is the loop in the beginning not executed when called from exec system call?
Invalidate the page table entries corresponding to the shared library pages; loop through the other page table entries{ if ( the entry is valid ){ free the corresponding page by invoking the release_page() function in the Memory Manager module; } Invalidate the page table entry; } Loop through the Disk Map Table entries of the process if (the entry is valid and is stack or heap) call release_block() function in the Memory Manager Module. set the entry to -1. return;Called by the exit_process function.
/* Lock all files to ensure that no processes are in the middle of a file operation */ For each valid entry in the Inode table Acquire lock on the file by calling the acquire_inode() function in the Resource Manager module. For each pid from 2 to MAX_PROC_NUM - 1 /* PID 0 is idle and 1 is init */ { /* This code is relevant only when the Pager Module is implemented in Stage 27 */Called by shutdown and logout system call.If pid == PID of Swapper Daemon /* Swapper Daemon must not be TERMINATED */ continue;If pid != pid of the current process AND state of the process in the process table entry is not TERMINATED Call exit_process() function from the Process Manager Module. } For each valid entry in the Inode table Release lock on the file by calling the release_inode() function in the Resource Manager module. return;