PROCESSES Todays Lecture Process Scheduling Job Types n
PROCESSES
Today’s Lecture Process Scheduling
Job Types n Jobs (Processes) can be described as either: l I/O-bound process – spends more time doing I/O than computations, many short CPU bursts l CPU-bound process – spends more time doing computations; few very long CPU bursts 3
Scheduling: The Big Picture n Consider a large computer system to which many jobs are submitted n Initially, jobs go to the secondary storage (disk) n Then, job scheduler chooses some of them to go to the memory (ready queue) n Then, CPU scheduler chooses from the ready queue a job to run on the CPU n Medium-term scheduler may move (swap) some partially-executed jobs from memory to disk (to enhance performance) 4
Scheduling: The Big Picture (cont’d) Midterm sched. Jobs Disk Job sched. CPU sched. In most small and interactive systems (UNIX, Win. XP, …), only the CPU scheduler exists 5
Schedulers n Long-term scheduler (or job scheduler) l Selects which processes should be brought into ready queue l Controls the degree of multiprogramming l Invoked infrequently (seconds, minutes) (can be slow) l Should maintain a ‘good mix’ of CPU-bound and I/O-bound jobs in the system n Short-term scheduler (or CPU scheduler) l selects which process should be executed next and allocates CPU l Short-term scheduler is invoked very frequently (milliseconds) (must be fast) n Medium-term scheduler l Swap processes in and out of the ready queue to enhance performance (i. e. , maintain the good mix of jobs) 6
Process Scheduling Queues n Processes migrate among various queues n Job queue – set of all processes in the system n Ready queue – set of all processes residing in main memory, ready and waiting to execute n Device queues – set of processes waiting for an I/O device 7
Process Lifetime 8
Operations on Processes Process Creation Process Termination Interprocess Communication
Process Creation n Parent process creates children processes, which, in turn create other processes, forming a tree of processes n Execution l Parent and children execute concurrently l Parent waits until children terminate n Resource sharing can take the form (depending on the OS): l Parent and children share all resources l Children share subset of parent’s resources l Parent and children share no resources 10
Process Creation: Unix Example n Process creates another process (child) by using fork system call l Child is a copy of the parent l Typically, child loads another program into its address space using exec system l Parent waits for its children to terminate 11
C Program Forking Separate Process int main() { pid_t pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf (stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp ("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for child to complete */ wait (NULL); printf ("Child Complete"); exit(0); Note: fork returns 0 to child and the pid of the } } new process to parent. 12
Process Termination n Process executes last statement and asks the operating system to delete it (exit) l Output data from child to parent (via wait) l Process’ resources are deallocated by operating system n Parent may terminate execution of children processes (abort) l Child has exceeded allocated resources l Task assigned to child is no longer required l If parent is exiting 4 Some operating system do not allow child to continue if its parent terminates – All children terminated - cascading termination 13
Cooperating Processes n Cooperating process can affect or be affected by the execution of another process n Why processes cooperate? l Information sharing l Computation speed-up l Modularity, Convenience n Interprocess Communications (IPC) methods l Shared memory l Message passing 14
- Slides: 14