forkAndExit

Document Sample

Shared by: Arvind Kiwelekar
Categories
Tags
Stats
views:
43
posted:
2/25/2009
language:
English
pages:
14
fork, exit, sleep, wakeup

Arvind W. Kiwelekar akiwelekar@gmail.com 02140262041



February 12, 2009



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Algorithm to Create a new Process

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



algorithm fork i n p u t : none o u t p u t t o p a r e n t p r o c e s s c h i l d PID number t o c h i l d p r o c e s s 0{ check f o r a v a i l a b l e k e r n e l r e s o u r c e s g e t f r e e p r o c t a b l e s l o t , u n i q u e PID number ; c h e c k t h a t u s e r i s n o t r u n n i n g t o o many p r o c e s s e s ; mark c h i l d s t a t e ” b e i n g c r e a t e d ” co py d a t a fro m p a r e n t p r o c t a b l e s l o t to c h i l d proc t a b e l s l o t ; i n c r e m e n t c o u n t on i n o d e o f PWD; i n c r e m e n t open f i l e c o u n t s i n t h e f i l e t a b l e , make co py o f p a r e n t c o n t e x t i n memory , push dummy s y s t e m l e v e l c o n t e x t l a y e r o n t o c h i l d system l e v e l c o n t e x t



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Algorithm to Create a new Process



16 17 18 19 20 21 22 23 24



i f ( e x e c u t i n g p r o c e s s i s parent p r o c e s s ){ chang e c h i l d s t a t e t o ” r e a d y t o r u n ” r e t u r n c h i l d ID } else { i n i t i l i z e u area timing f i e l d ; return 0; } } // f o r k



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Algorithm to terminate a process

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16



algroithm exi t i n p u t : r e t u r n co de f o r p a r e n t p r o c e s s o u t n o n e : none { ignore a l l signals ; i f ( p r o c e s s i s group l e a d e r with a s s o c i a t e d c o n t r o l t e r m i n a l ){ s e n d hangup s i g n a l t o a l l members o f p r o c e s s g r o u p r e s e t p r o c e s s group f o r a l l members t o 0 } c l o s e a l l open f i l e s / / ( c l o s e ( ) ) r e l e a s e c u r r e n t w o r k i n g d i r e c t o r y // i p u t f r e e r e g i o n s a s s o c i t e d w i t h p r o c e s s // f r e e r e g }



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Algorithm to terminate a process



17 18 19 20 21 22 23 24 25



write accounting record make p r o c e s s s t a t e zo mbie a s s i g n p a r e n t p r o c e s s ID o f a l l c h i l d p r o c e s s e s t o be i n i t p r o c e s s i f any c h i l d p r o c e e s i s zombie , send death of c h i l d s i g n a l to i n i t send death of c h i l d s i g n a l to parent p ro c e s s context switch }



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep Algorithm



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep Algorithm

Logical Model

0..n Process sleeps 1..1 Event 0..n maps 1..1 Address



process 1 process 2 process 3 process 4



awaiting for I/O Completion



1001



waiting for buffer



1011



waiting for inode process 5 process 6 waiting for ternimanl i/p process 7



1021



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep Algorithm



Data Structures Used to Implement Sleep Algo.

1001 1021 1031 P1 P4 P7 Queue of Sleeping Processes P2 P3



f(Event) = sleep Address

Hash



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep

input 1. Sleep Address 2. Priority output For iterrupted sleep 1 and 0 for un-interrupted sleep

1 2 3 4 5 6 7



r ais e processor execution l e v e l to block a l l i n t e r r u p t s s e t p ro c e s s s t a t e to s l e e p put p r o c e s s on s l e e p hash queue b a s e d on s l e e p a d d r e s s save s l e e p address in process t a b l e s l o t s e t p ro c e s s p r i o r i t y to i n p u t p r i o r i t y l e v e l



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep



8 9 10 11 12 13 14



i f ( p r o c e s s s l e e p i s NOT i n t e r r u p t i b l e ) { do c o n t e x t s w i t c h // p r o c e s s r e s u m e s e x e c u t i o n h e r e when i t wakes up r e s e t p r o c e s s o r p r i o r i t y l e v e l to a l l o w i n t e r r u p t s a s when p r o c e s s went t o s l e e p return (0); }



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep



15 16 17 18 19 20 21 22 23



i f ( no s i g n a l i s p e n d i n g a g a i n s t p r o c e s s ) { do c o n t e x t s w i t c h /∗ p r o c e s s r e s u m e s e x e c u t i o n h e r e when i t wakes up ∗/ i f ( no s i g n a l i s p e n d i n g a g i a n s t p r o c e s s ) { r e s e t p r o c e s s o r p r i o r i t y l e v e l to what i t was when p r o c e s s went t o s l e e p return (0) } }



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



Process Sleep



25 26 27 28 29 30



remove p r o c e s s fro m s l e e p h a s queue r e s e t p r o c e s s o r p r i o r i t y l e v e l t o what i t was when p r o c e s s went t o s l e e p i f ( p ro c e s s s l e e p p r i o r i t y s e t to catch s i g n a l s ) return (1) do l o n g j m p a l g o r i t h m



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup



wakeup algorithm

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



r ais e processor execution l e v e l to block a l l i n t e r r u p t s f i n d s l e e p hash queue f o r s l e e p a d d r e s s f o r ( e v e r y p r o c e s s a s l e e p on s l e e p a d d r e s s ) { remove p r o c e s s fro m h a s h q u e u e mark p r o c e s s s t a t e ” r e a d y t o r u n ” clear f i e l d in process table entry for sleep address i f ( p r o c e s s n o t l o a d e d i n memory ) wakeup s w a p p e r p r o c e s s ( 0 ) e l s e i f ( awakened p r o c e s s i s more e l i g i b l e t o r u n than c u r r e n t l y running p ro c e s s ) set scheduler flag } r e s t o r e p r o c e s s o r e xe c u t i o n l e v e l to o r i g i n a l l e v e l



Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 fork, exit, sleep, wakeup




Share This Document


Other docs by Arvind Kiwelek...
design1
Views: 26  |  Downloads: 8
Bulding Analysis Model
Views: 249  |  Downloads: 8
Introduction To Software Engineering LectNo1
Views: 1002  |  Downloads: 44
signal
Views: 84  |  Downloads: 10
marks
Views: 50  |  Downloads: 10
IPCAssignment
Views: 46  |  Downloads: 14
Process Creation and Termination
Views: 96  |  Downloads: 4
Lect 3
Views: 52  |  Downloads: 4
ThreadAssignment
Views: 51  |  Downloads: 16
OtherIPCMechanisms
Views: 44  |  Downloads: 20
by registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!