Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

Chapter 2: Processes - Exercises

ANSWERS

1. What are the differences between multiprogramming and time-sharing?


Multiprogramming - When one job needs to wait for I/O, the processor can switch to the other job Time Sharing multiple users simultaneousl !uantum access the s stem with time

2. Draw the complete five State Process Model. Dispatch (ead+ &imeout )vent occurs ,loc-e d . What is suspended process? !ive and e"plain two #2$ suspended states.
"rocesses waiting for I/O are swapped to dis# to free up more memor $ a$ %loc#ed/Suspend a process in secondar memor and awaiting an e&ent$ b$ 'ead /Suspend - a process in secondar memor but a&ailable for e(ecute as soon as it is loaded into main memor $

*ew

'dmit

(unnin

(elease

)"it

)vent Wait

%. Draw the Process State &ransition Diagram with one Suspend states. Lukiskan gambar rajah peralihan keadaan proses dengan satu keadaan Suspend.

.. !ive &W/ #2$ e"amples of events that cause a state transition for a process from (0**1*! to ()'D2. Berikan DUA (2) contoh peristiwa ang men ebabkan pertukaran keadaan bagi proses daripada !U""#"$ kepada !%AD&. )nswer/*awapan+ ',--I-.----'/)01+ The most commonl #nown situation is that currentl running process has ta#en its share of time for e(ecution 2Time out3$ )lso, in some e&ents a process ma ha&e to be admitted from running to read if a high priorit process has occurred$

3. What is a process? )"plain how operating s+stem does to create a new process. Apakah ia satu proses. 'elaskan bagaimanakah ang dilakukan oleh sistem pengoperasian untuk mencipta suatu proses ang baru.
) program in e(ecution$ )n instance of a program running in a computer$ The entit that can be assigned to and e(ecuted on a processor$ ) unit of acti&it characteri4ed b the e(ecution of a se!uence of instructions, a current state and associated set of s stem resources$ 2)n answer acceptable3 To a$ b$ c$ d$ e$ create a new process, it can proceed as follows+ )ssign a uni!ue process identifier to the new process$ )llocate space for the process$ Initiali4e the process control bloc#$ Set the appropriate lin#ages$ 5reate or e(pand other data structures$

4. 5ist three general categories of information in a process control bloc-. Senaraikan tiga kategori(kategori am bagi maklumat ang terkandung dalam blok kawalan proses.
"rocess identification "rocessor state information$ "rocess control information$

6. !ive and e"plain five states of process model. Beri dan terangkan mengenai model lima keadaan proses.
-ew - ) process that just been created but has not et been admitted to the pool of e(ecutable processes b the operating s stem 'ead - ) process that is prepared to e(ecute when gi&en the opportunit 'unning - The process that is currentl being e(ecuted$ %loc#ed - ) process that cannot e(ecute until some e&ent occurs, such as the completion of an I/O operation /(it - ) process that has been released from the pool of e(ecutable processes b the operating process

7. What are the steps performed b+ an operating s+stem to create a new process? Apakah langkah(langkah ang dilaksanakan oleh sistem pengoperasian untuk membentuk proses baru.
)ssign a uni!ue process identifier )llocate space for the process Initiali4e process control bloc# Set up appropriate lin#ages /g+ add new process to lin#ed list used for scheduling !ueue 5reate of e(pand other data structures /g+ maintain an accounting file

18. ,ased on the information below9 do the trace of processes. 'ssume /perating S+stem allows a process to e"ecute for ma"imum three instruction c+cles9 after which it is interrupted. Start with process '. Berdasarkan maklumat di bawah) laksanakan pengesanan proses(proses. Andaikan sistem pengoperasian membenarkan proses melaksanakan tiga kitaran arahan) selepas itu ian a akan disampuk. *ulakan dengan proses A.
'ddress

8 288 .88

Main Memor+ Dispatcher Process A . instructions Process B % instructions9 then re;uest an 1</ action Process C 4 instructions Dispatcher e"ecutes 2 instructions code

Program =ounter

688 Process '

688 Process , 1%88 Process =

11. !ive four t+pes of relationship between thread and process implementation normall+ used with e"ample of operating s+stem using that method. Berikan empat jenis perlaksanaan hubungan diantara bebenang dan prosses ang biasa digunakan beserta contoh sistem pengoperasi ang menggunakan kaedah tersebut.
One process one thread eg$ msdos One process multiple threads eg$ *a&a run-time en&ironment Multiple processes one thread per process eg$ ,-I6 Multiple processes multiple threads per process eg$ Solaris

12. :ow is the e"ecution conte"t of a process used b+ the operating s+stem. (Bagaimanakah +e,ecution conte,t+ bagi sesuatu proses digunakan oleh sistem pengoperasian).

5ontains the process elements 5reated and manage b the operating s stem )llows support for multiple processes

1 . What is instruction trace? (Apakah dia penjejak arahan-).


Se!uence of instruction that e(ecute for a process 0ispatcher switches the processor from one process to another

1%. 5ist four characteristics of a suspended process. (Senaraikan empat ciri proses tergantung)
> > > > "rocessor is faster than I/O so all processes could be waiting for I/O Swap these processes to dis# to free up more memor %loc#ed state becomes suspend state when swapped to dis# Two new states > %loc#ed/Suspend > 'ead Suspend

1.. Process =ontrol ,loc- contains specific information stored in a data structure. Describe four #%$ elements of the P=, that characteri?e the process Blok .engawalan .roses (./B) mengandungi maklumat tertentu ang disimpan di dalam struktur data. 0erangkan empat (1) elemen ./B ang memperincikan sesuatu proses. Identifier7 uni!ue id to distinguish among process State7 running, read , suspend/bloc# "riorit le&el relati&e to other process "rogram counter7 the address of the ne(t instruction to be e(ecuted in main memor Memor "ointers 5onte(t data I/O status information

13. =onsider the e"ecution of four processes9 each of them loaded into main memor+ as shown 'ddress below@ Main Memor+ 8 288 Dispatcher Process ' 3 instructions 1388 Process , % instructions9 then re;uest an 1</ action Process = 3 instructions Process ' Process D . instructions Dispatcher e"ecutes instructions code 2688 Process , 1%888 Process = 28888 Process D

'ssume the operating s+stem allows a process to continue e"ecution for a ma"imum of instruction c+cles9 after which it is interrupted. Show the combined trace of the four processes using the information given above.
)nswer+ Trace of processes "rocess ) 89:: 89:8 89:; 89:< 89:= 89:> 5ombined trace+ 89:: 89:8 89:; -------Time out 200 201 202 ;?:: ;?:8 ;?:; -------Time out 200 201 202 8=::: 8=::8 8=::; -------Time out "rocess % ;?:: ;?:8 ;?:; ;?:< "rocess 5 8=::: 8=::8 8=::; 8=::< 8=::= 8=::> "rocess 0 ;:::: ;:::8 ;:::; ;:::< ;:::=

200 201 202 ;:::: ;:::8 ;:::; -------Time out 200 201 202 89:< 89:= 89:> -------Terminate 200 201 202 ;?:< -------I/O re!uest

200 201 202 8=::< 8=::= 8=::> -------Terminate 200 201 202 ;:::< ;:::= -------Terminate

Threads Exercises: 1. 5ist reasons wh+ a mode switch between threads ma+ be cheaper than a mode switch between processes. #A %.2$ )nswer+ @ess state information is in&ol&ed$

2. =onsider a multiprocessor s+stem and a multithreaded program written using man+-to-man+ threading model. 5et the number of user-level threads in the program be more than the number of processors in the s+stem. Discuss the performance implications of the following scenarios@ a. &he number of -ernel threads allocated to the program is less than the number of processors. b. &he number of -ernel threads allocated to the program is e;ual to the number of processors. c. &he number of -ernel threads allocated to the program is greater than the number of processors but less than the number of user-level threads. #S!! %.3$ )nswer+ When a number of #ernel threads is less than the number of processors, then some of the processors would remain idle since the scheduler maps onl #ernel threads to processors and not user-le&el threads to processors$ When the number of #ernel threads is e(actl e!ual to the number of processors, then it is possible that all of the processors might be utili4ed simultaneousl $ Aowe&er, when a #ernel-thread bloc#s inside the #ernel 2due to a page fault or while in&o#ing s stem calls3, the corresponding processor would remain idle$ When there are more #ernel threads than processors, a bloc#ed #ernel thread could be swapped out in fa&our of another #ernel thread that is read to e(ecute, thereb increasing the utili4ation of the multiprocessor s stem$

!ive TWO (2) general e"amples of the use of threads in a single-user multiprocessing s+stem.

)nswer+
Boreground/bac#ground wor#7 as nchronous processing7 speedup of e(ecution b parallel processing of data7 modular program structure$

%.

Windows9 Solaris9 5inu"9 Mach9 and /S<2 are the e"amples of operating s+stems that support multiple threads. 2indows) Solaris) Linu,) *ach) dan 3S42 adalah contoh(contoh sistem pengoperasian ang men okong pelbagai bebenang.

a. What is thread? Apakah bebenangb. )"plain the concept of multithreading. 'elaskan konsep multi(bebenang. c. !ive &W/ #2$ benefits of using thread? Berikan DUA (2) 5aedah menggunakan bebenang)nswer+ a$ b$ Thread- lightweight process, a unit of e(ecution Multithreading+ ) program, which splits up into se&eral threads, is said to be multithreading Operating s stem supports multiple threads of e(ecution within a single process

c$ -

%enefits of thread+ Ta#es less time to create a new thread than a process @ess time to terminate a thread than a process @ess time to switch between two threads within the same process Since threads within the same process share memor and files, the can communicate with each other without in&o#ing the #ernel

..

What does a process do to start another process?


It ma#es a s stem call that creates a new 2child3 process$ 0epending on the OS and the e(act call used, this child process ma be an entirel different program or it ma be a cop of the parent process$ This call might be a Cfor#,D e(ec,D Cshell,D or CcloneD call, depending on the OS$

3.

Distinguish between a process and a thread.


) process is a program that is running$ ) than a process$ )t an gi&en point in the can sa&e the processor conte(t 2registers start e(ecuting the process anew, perhaps thread is something less e(ecution of a process we and stac# space3 and at another point in the

process$ /ach separate running 2or waiting3 processor conte(t within a process is called a thread$ Threads within a single process share address spaces and are thus less e(pensi&e to switch among than are processes$

4.

Wh+ do we usuall+ sa+ that -ernel level threads are better than user level threads?
The OS #ernel is aware of #ernel le&el threads, so that if one thread of a process ma#es a bloc#ing OS call, the OS can dispatch another thread from that process with minimum conte(t switching o&erhead$ In order to accomplish such o&erlap with user le&el threads, the application must resort to as nchronous I/O and other OS calls - a much more comple( tas#$

6.

' thread is sometimes called as a lightweight process. &he table below refers to two of the relationships between threads and processes. Bebenang juga dikenali sebagai pecahan proses atau proses ringan. 'adual di bawah merujuk kepada dua perhubungan antara bebenang dan proses. Describe each of the relationships below. 0erangkan setiap perhubungan di bawah. Threads : Process 1@1 ) thread ma migrate from one process en&ironment to another$ This allows a thread to be easil mo&ed among distinct s stems$ Description /ach thread of e(ecution is a uni!ue process with its own address space and resources$

1@M

7.

5ist &W/ #2$ benefits of threads over processes. Senaraikan DUA (2) kelebihan bebenang berbanding proses.
Ta#es less time to create a new thread than a process @ess time to terminate a thread than a process @ess time to switch between two threads within the same process Thread can communicate with each other without in&o#ing the #ernel

18.

!ive the differences between user-level threads and -ernel-level threads. Berikan perbe6aan di antara bebenang tahap(pengguna dan bebenang tahap(inti.
E E ,@T )ll thread management is done b the application The #ernel is not aware of the e(istence of threads F@T Fernel maintains conte(t information for the process and the threads Scheduling is done on a thread basis

11.

Define multithreading. De5inisikan multi(bebenang.


Multithreading is a techni!ue in which a process, e(ecuting application, is di&ided into threads that can run concurrentl $ an

You might also like