Lecture 1 and 2  processes
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Lecture 1 and 2 processes

  • 230 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
230
On Slideshare
230
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Rushdi Shams, Dept of CSE, KUET 1 “There are 10 types of people in the world- who understands binary and who does not”
  • 2. Process Concept  Process is a program in execution; process execution must progress in sequential fashion  A process includes: 1. Text Section: Program code. Text files have a program code which is different than program codes of E-mail programs 2. Program counter: Represents the current state of the process 3. Stack: Contains temporary data like method parameters, return addresses 4. Data section: Contains global variables Rushdi Shams, Dept of CSE, KUET 2
  • 3. Process State  As a process executes, it changes state. This state is noticed by the program counter. new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a processor terminated: The process has finished execution Rushdi Shams, Dept of CSE, KUET 3
  • 4. Diagram of Process State Rushdi Shams, Dept of CSE, KUET 4
  • 5. Process Control Block (PCB) Information associated with each process  Process state  Program counter  CPU registers  CPU scheduling information  Memory-management information  I/O status information Rushdi Shams, Dept of CSE, KUET 5
  • 6. Process Control Block (PCB) 6Rushdi Shams, Dept of CSE, KUET
  • 7. CPU Switch From Process to Process 7Rushdi Shams, Dept of CSE, KUET
  • 8. Process Scheduling Queues  Job queue – set of all processes in the system  Ready queue – set of all processes residing in main memory, ready and waiting to execute  Device queues – set of processes waiting for an I/O device  Processes migrate among the various queues Rushdi Shams, Dept of CSE, KUET 8
  • 9. Representation of Process Scheduling 9Rushdi Shams, Dept of CSE, KUET
  • 10. Schedulers  Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue  Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU Rushdi Shams, Dept of CSE, KUET 10
  • 11. Schedulers (Cont.)  Short-term scheduler is invoked very frequently milliseconds must be fast  Long-term scheduler is invoked very infrequently seconds, minutes may be slow  The long-term scheduler controls the degree of multiprogramming Rushdi Shams, Dept of CSE, KUET 11
  • 12. Mathematics!  If a process is required 10 milliseconds to be decided for a GO and it takes 100 milliseconds to execute then the CPU usage for that particular task is- 110 ms process requires 10 ms to be decided 1 ms process requires 10/110 ms to be decided 100 ms process requires ??? ms to be decided 9% of the CPU was used to accomplish that process Rushdi Shams, Dept of CSE, KUET 12
  • 13. Mathematics!  If a process is required 100 seconds to be decided for a GO and it takes 1000 seconds to execute then the CPU usage for that particular task is- 1100 s process requires 100 s to be decided 1 s process requires 100/1100 s to be decided 100 s process requires ??? s to be decided 9% of the CPU was used to accomplish that process Rushdi Shams, Dept of CSE, KUET 13
  • 14. Mathematics!  Which process should be scheduled by Long term scheduler? Justify your statement Rushdi Shams, Dept of CSE, KUET 14
  • 15. The Process Model  Conceptually, each process has its own virtual CPU  In reality, the real CPU switches back and forth from process to process  This procedure is called pseudoparallelism. Rushdi Shams, Dept of CSE, KUET 15
  • 16. Rushdi Shams, Dept of CSE, KUET 16
  • 17. Rushdi Shams, Dept of CSE, KUET 17
  • 18.  A Computer Engineer is making cake today.  In his kitchen, he has a book- “how to bake cake”  He also has ingredients like- flour, baking soda, custard powder, etc. Rushdi Shams, Dept of CSE, KUET 18
  • 19.  The book is the program (algorithm)  The computer engineer is the CPU  The ingredients are input data (remember global and local variables??)  The process is the activity consisting of our baker reading the book, fetching the ingredient and baking the cake! Rushdi Shams, Dept of CSE, KUET 19
  • 20.  Now, his youngest son came to the kitchen  He alleged to his father that he has been attacked by cockroaches and they had a bite on him!  His father stops baking  The computer engineer took the first aid box and aided his son Rushdi Shams, Dept of CSE, KUET 20
  • 21.  The son is the interrupt program  The first aid box is a different program  The injection, medicines in the box are data need to run the program  And of course, aiding son is more high prioritized process than baking cakes!  The engineer after aiding his son comes back to the kitchen and then again bakes cakes! Rushdi Shams, Dept of CSE, KUET 21
  • 22. Process Creation  Three principal reasons for which a process is created. 1. System initialization when the OS is booted, several processes are created. Some of them are foreground processes, others are background processes. Rushdi Shams, Dept of CSE, KUET 22
  • 23.  Background processes designed to deal with incoming mails sleep. Whenever a mail comes, they wake.  Processes that stay in background to handle some activity like email, web pages, printing are called Daemons. Rushdi Shams, Dept of CSE, KUET 23
  • 24. Process Creation 2. Process created by other process mostly done by system calls. In network sharing, one process may collect the stream of bytes and store them, other maintains the buffer while introduced by the first one. Rushdi Shams, Dept of CSE, KUET 24
  • 25. Process Creation 3. Process created by a user request Whatever you click and do on Windows platform, with every single click, there is a possibility to create a new thread!!  Rushdi Shams, Dept of CSE, KUET 25
  • 26. Process Creation  In UNIX, there is only one system call to create new process: FORK  This call creates an exact clone of the calling process.  After the FORK, two processes- child and parent have the same memory image, environment strings, same everything!  The child process then executes EXECVE to change its memory image and run a new program Rushdi Shams, Dept of CSE, KUET 26
  • 27. Process Creation  The reason for this two step process is like a reservation in bus ticket. The OS is alerted that with the procedure. Secondly, the child process gets plenty of time to decide whether it’s going to purchase or decline that ticket!  Windows does not have such FORKING. It uses CreateProcess system call and the child is created straight away! Rushdi Shams, Dept of CSE, KUET 27
  • 28. Process Termination  Sooner or later the new process will terminate- 1. Normal Exit (voluntary) Simply, when you close a window on Windows, the process(es) related to it have their normal exit Rushdi Shams, Dept of CSE, KUET 28
  • 29. Process Termination 2. Error Exit (voluntary)  How many times your compiler reported error to you during compiling?  Screen oriented platforms like Windows, however, uses a hybrid of Normal Exit and Error Exit in such cases! Rushdi Shams, Dept of CSE, KUET 29
  • 30. Process Termination 3. Fatal Error (Non-voluntary) this error is caused by the process itself, normally due to the program bug. Referencing non-existing memory location or divide by zero problems cause such errors and process termination Rushdi Shams, Dept of CSE, KUET 30
  • 31. Process Termination 4. Killed by another process In UNIX, the system call is KILL. In Windows, the call is TerminateProcess. In both cases, the KILLER must have the proper authorization to kill the KILLEE.  In some systems, when a process terminates, all processes it creates die. UNIX and Windows-none of them works in this fashion. Rushdi Shams, Dept of CSE, KUET 31