This document discusses process management in an operating system. It describes how processes can be suspended, resumed, created, terminated, and have their priorities changed. Key points include:
- Processes can be suspended temporarily by changing their state to suspended. This pauses execution until resumed.
- Resume changes the process state back to ready, adding it to the ready queue so it is eligible for CPU time again.
- Create allocates resources for a new process and lays out its initial stack. It sets the process to a suspended state initially.
- Kill immediately stops a process, removing it from all queues and freeing its resources. It handles different states like ready or waiting.
This document discusses process management in an operating system. It describes how processes can be suspended, resumed, created, terminated, and have their priorities changed. Key points include:
- Processes can be suspended temporarily by changing their state to suspended. This pauses execution until resumed.
- Resume changes the process state back to ready, adding it to the ready queue so it is eligible for CPU time again.
- Create allocates resources for a new process and lays out its initial stack. It sets the process to a suspended state initially.
- Kill immediately stops a process, removing it from all queues and freeing its resources. It handles different states like ready or waiting.
This document discusses process management in an operating system. It describes how processes can be suspended, resumed, created, terminated, and have their priorities changed. Key points include:
- Processes can be suspended temporarily by changing their state to suspended. This pauses execution until resumed.
- Resume changes the process state back to ready, adding it to the ready queue so it is eligible for CPU time again.
- Create allocates resources for a new process and lays out its initial stack. It sets the process to a suspended state initially.
- Kill immediately stops a process, removing it from all queues and freeing its resources. It handles different states like ready or waiting.
This document discusses process management in an operating system. It describes how processes can be suspended, resumed, created, terminated, and have their priorities changed. Key points include:
- Processes can be suspended temporarily by changing their state to suspended. This pauses execution until resumed.
- Resume changes the process state back to ready, adding it to the ready queue so it is eligible for CPU time again.
- Create allocates resources for a new process and lays out its initial stack. It sets the process to a suspended state initially.
- Kill immediately stops a process, removing it from all queues and freeing its resources. It handles different states like ready or waiting.
Maths, GMIT 1 November 06 Process Management 1 Process Management have already talked about moving processes between ready and current states now look at how processes are created and terminated introduce new process state - suspend look at the routines that move processes November 06 Process Management 2 Suspension & Resumption process temporarily stopped suspended animation used when process has to wait for particular restart conditions does not know when they will occur first, define two processes suspend - to stop a process resume - to restart a process suspended process will not be eligible for CPU service November 06 Process Management 3 Suspension & Resumption new process state used suspended - distinguishes from ready and current processes diagram illustrates the transition between these states suspend must verify that the process to suspend is either READY or CURRENT resume needs an argument specifying the process to be restarted must also verify current state is suspended November 06 Process Management 4 Transition READY CURRENT SUSPENDED create Suspend resume suspend resched resched November 06 Process Management 5 Suspension & Resumption process suspension function suspend passed an argument to specify process to suspend verify that process is valid process is either ready or current change state recorded in process table remove process from ready list (away from resched) currently executing process can suspend itself reschedule to allow another process to execute November 06 Process Management 6 Suspend SYSCALL suspend(int pid) { struct pentry *pptr; /* pointer to proc. tab. entry */ int ps; /* saved processor status */ int prio; /* priority returned */ disable(ps); if (isbadpid(pid) || pid==NULLPROC || ( (pptr= &proctab[pid])->pstate !=PRCURR && pptr->pstate!=PRREADY) ) { restore(ps); return(SYSERR); } (contd) Systems Software - Process Management November 06 Damien Costello, Dept of Computing & Maths, GMIT 2 November 06 Process Management 7 Suspend SYSCALL suspend( int pid) contd... if (pptr->pstate == PRREADY) { dequeue(pid); pptr->pstate = PRSUSP; } else { pptr->pstate = PRSUSP; resched(); } prio = pptr->pprio; restore(ps); return(prio); } November 06 Process Management 8 Suspend if process is in ready state must be removed from ready list moved to suspended state if process is current, then it marks as suspended calls resched will now switch context without moving process to ready list this process not considered by resched November 06 Process Management 9 Suspension & Resumption process resumption function resume moves process from suspended state back to ready state then eligible for CPU service takes argument specifying process to restart verify process is suspended verify that pid is valid not done by ready function November 06 Process Management 10 Suspension & Resumption move process back to ready list calls ready(pid) to do this change state returns the priority of the process to calling function returns SYSERR November 06 Process Management 11 Resume SYSCALL resume(int pid) { int ps; /* saved processor status */ struct pentry *pptr /* ptr to process table entry */ int prio; /* priority to return */ disable(ps); if ( isbadpid(pid) || ( pptr = &proctab[pid])->pstate != PRSUSP) { restore(ps); return(SYSERR); } prio = pptr->prio; ready (pid); resched (); restore (ps); return (prio); } November 06 Process Management 12 Process Control SYSERR return SYSERR to indicate unacceptable arguments or that something else prevented successful completion OK used by routines that dont return values to the calling function to indicate successful completion Systems Software - Process Management November 06 Damien Costello, Dept of Computing & Maths, GMIT 3 November 06 Process Management 13 System Calls precautions taken by resume make it a system call general purpose routine that can be invoked at any time define the exterior of the operating system provide interface through which the user has access to all system services executing a system call (like resume) changes the process table and other system data structures (q structure) November 06 Process Management 14 System Calls only one process table shared by all processes must ensure exclusive access when changing the table must not call resched may cause a context switch to a process which wants to change the process table rescheduling can also be caused by an interrupt (later) to prevent interrupts system calls use the disable function records current interrupt state (FLAGS register) disables processor interrupts returns recorded interrupt state November 06 Process Management 15 System Calls before exiting system call, process calls restore resets the interrupt state to original value cannot just enable interrupts before returning to caller caller may have been executing with interrupts disabled there restore to original value November 06 Process Management 16 Disable and Restore disable records the current value of the FLAGS register disables interrupts returns recorded FLAGS value in reality, an assembly flag program for accessing register Restore deposits its argument into the FLAGS register used in pairs around uninterruptable code November 06 Process Management 17 Suspend and Resume do not maintain separate linked list of suspended processes as ready does reason ready processes kept on list to speed search for highest priority process during rescheduling system never searches through suspended processes looking for one to resume no need to maintain list November 06 Process Management 18 Process Termination suspend freezes processes can be resumed later kill stops process immediately and removes from system frees the process table entry eradicates entire record, cannot be restarted actions taken by kill depend on process state if process is ready, sleeping or waiting all on list => must be dequeued Systems Software - Process Management November 06 Damien Costello, Dept of Computing & Maths, GMIT 4 November 06 Process Management 19 Process Termination if waiting for semaphore must adjust semaphore count what does kill do for a ready process? checks pid to ensure valid active process id in correct range process table entry is not empty decrements numproc (global variable) calls freestk to free memory unlinks the process from the ready list with dequeue frees the process table entry by setting pstate to PRFREE November 06 Process Management 20 Process Termination if process is current validate and decrement as before if current is the last process, then xdone is called xdone prints a system termination message and terminates PC-XINU marks the current process state PRFREE and then resched to pass control November 06 Process Management 21 Process Termination SYSCALL kill( int pid) { struct pentry *pptr; int ps; disable(ps); if (isbadpid(pid) || ( pptr= &proctab[pid])->pstate ==PRFREE) { restore(ps); return(SYSERR); } if (--numproc == 0) xdone(); freestk(pptr->pbase, pptr->len); November 06 Process Management 22 Process Termination switch (pptr->pstate) { case PRCURR: pptr->pstate = PRFREE; /* suicide */ resched(); break; case PRWAIT: semaph[pptr->psem].semcnt++; /* fall through */ case PRSLEEP: case PRREADY: dequeue(pid); break; default: pptr->pstate = PRFREE; break; } restore(ps); return(OK); } November 06 Process Management 23 Process Creation Process Creation create - creates new independent process lay down an image of the process as if it had been stopped while running then ctxsw can switch to it create finds a free (unused) slot in the process table (newpid) allocate space for the new process stack fill the process table entry November 06 Process Management 24 Process Creation create uses the function newpid to search for a free process id returns SYSERR if none found uses procedures roundew to round the stack size to the next largest even word uses getmem to allocate space for stack the initial stack is created by pushing values onto it simulates a procedure call Systems Software - Process Management November 06 Damien Costello, Dept of Computing & Maths, GMIT 5 November 06 Process Management 25 Process Creation new process behaves as if it had been called from another procedure create fills the process table entry sets the pregs field to point to the top of the new stack value for the FLAGS register is the most important process should begin execution with interrupts enabled FLAGS register interrupt bit is set November 06 Process Management 26 Process Creation create sets pstate to PRSUSP suspended but ready to run returns pid of newly created process pid must be passed to resume to start process November 06 Process Management 27 Utility - getprio SYSCALL getprio(int pid) { struct pentry *pptr; int ps; disable(ps); if (isbadpid(pid) || ( pptr = &proctab[pid])->pstate == PRFREE) { restore(ps); return(SYSERR); } restore(ps); return(pptr->pprio); } November 06 Process Management 28 Utility - getpid SYSCALL getpid(void) { return(currpid); } November 06 Process Management 29 Utility - chprio SYSCALL chprio(int pid, int newprio) { int oldprio; struct pentry *pptr; int ps; disable(ps); if (isbadpid(pid) || newprio<=0 || (pptr = &proctab[pid])->pstate == PRFREE) { restore(ps); return(SYSERR); } oldprio = pptr->pprio; pptr->pprio =newprio; restore(ps); return(oldprio); }