1 / 36

Chapter 3 Process Scheduling

Chapter 3 Process Scheduling. Bernard Chen Spring 2007. Outline. Process Concept Process Scheduling Process Operation. Process Concept.

Download Presentation

Chapter 3 Process Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Process Scheduling Bernard Chen Spring 2007

  2. Outline • Process Concept • Process Scheduling • Process Operation

  3. Process Concept • Early computer systems allow only one program running at a time. In contrast, current day computer systems allow multiple programs to be loaded into memory and executed concurrently. • Process concept makes it happen

  4. The Process Process: a program in execution • Text section: program code • program counter (PC) • Stack: to save temporary data • Data section: store global variables • Heap: for memory management

  5. Process in Memory

  6. Stack and Queue • Stack: First in, last out • Queue: First in, first out • Do: push(8) push(17) push(41) pop() push(23) push(66) pop() pop() pop()

  7. Heap (Max Heap) Provide O(logN) to find the max 97 53 59 26 41 58 31 16 21 36

  8. The Process • Program itself is not a process, it’s a passive entity • A program becomes a process when an executable (.exe) file is loaded into memory. • Process: a program in execution

  9. The Process • Although two processes may be the same program, they are considered two separate execution sequences. • They may share the same text section, but data, heap, stack section vary.

  10. Process State • 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 process • terminated: The process has finished execution

  11. Diagram of Process State

  12. Process Control Block (PCB) • Each process is represented in a operating system by a Process Control Block (PCB) • Process state • Program counter (PC) • CPU scheduling information (Ch5) • Memory-management information (Ch8) • Accounting information • I/O status information

  13. CPU Switch From Process to Process

  14. Process Scheduling • As processes entered the system, they are put into job queue • The processes that are stay in main memory and are ready and waiting to execute are kept on a list called ready queue • A ready queue contains pointers to the first and final PCBs in the list • The list of processes waiting for a particular I/O is called a device queue

  15. Ready Queue And Various I/O Device Queues

  16. Queueing Diagram • A common representation for discussion for of process scheduling is a queueing diagram

  17. Queueing Diagram A new process is initially put in the ready queue, once the process is located in CPU, one of several events may occur: • The process issue a I/O request, and then be placed in I/O queue • The process create a new subprogram and wait for the subprocess’ termination • The process could be remove from CPU and be placed back to ready queue

  18. Queueing Diagram

  19. 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

  20. Schedulers • 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

  21. Schedulers Processes can be described as either: • I/O-bound process–spends more time doing I/O than computations, many short CPU bursts • CPU-bound process–spends more time doing computations; few very long CPU bursts

  22. Schedulers • On some systems, the long-term scheduler maybe absent or minimal • Just simply put every new process in memory for short-term scheduler • The stability depends on physical limitation or self-adjustment nature of human users

  23. Schedulers • Sometimes it can be advantage to remove process from memory and thus decrease the degree of multiprogrammimg • This scheme is called swapping

  24. Addition of Medium Term Scheduling

  25. Process Creation • A process may create several new processes. The creating process is called a parent process, and new processes are called children process • Each of these processes may create other processes, forming a tree processes • Most OS identify processes according to a unique process identifier (pid) which is typically an integer

  26. Process Tree

  27. Process Creation Resource sharing • Parent and children share all resources • Children share subset of parent’s resources (such as memory of files) • Parent and child share no resources (MPI programming)

  28. Process Creation Execution • Parent and children execute concurrently • Parent waits until children terminate

  29. Process Creation • UNIX examples • Fork system call creates new process • Exec system call used after a fork to replace the process’ memory space with a new program • Both processes (parent and child) continue execution after fork(), with one difference: the return code for the fork() is zero for child processes.

  30. Process Creation

  31. C Program Forking Separate Process

  32. Share Memory Parallelization System Example m_set_procs(number): prepare number of child for execution m_fork(function): childes execute “function” m_kill_procs(); terminate childs

  33. Real Example main(argc , argv) { int nprocs=9; m_set_procs(nprocs); /* prepare to launch this many processes */ m_fork(slaveproc); /* fork out processes */ m_kill_procs(); /* kill activated processes */ } void slaveproc() { int id; id = m_get_myid(); m_lock(); printf(" Hello world from process %d\n",id); printf(" 2nd line: Hello world from process %d\n",id); m_unlock(); }

  34. Real Example int array_size=1000 int global_array[array_size] main(argc , argv) { int nprocs=4; m_set_procs(nprocs); /* prepare to launch this many processes */ m_fork(sum); /* fork out processes */ m_kill_procs(); /* kill activated processes */ } void sum() { int id; id = m_get_myid(); for (i=id*(array_size/nprocs); i<(id+1)*(array_size/nprocs); i++) global_array[id*array_size/nprocs]+=global_array[i]; }

  35. Process Termination • Process executes last statement and asks the operating system todelete it (exit) • Output data from child to parent (via wait) • Process’resources are deallocated by operating system

  36. Process Termination • Parent may terminate execution of children processes (abort) • Child has exceeded allocated resources • Task assigned to child is no longer required • If parent is exiting, some operating system do not allow child to continue if its parent terminates

More Related