Docsity

Lecture Notes on Processes - Advance Operating Systems | CS 4210, Study Guides, Projects, Research of Operating Systems

Partial preview of the text

Download Lecture Notes on Processes - Advance Operating Systems | CS 4210 and more Study Guides, Projects, Research Operating Systems in PDF only on Docsity!

Chapter 3: ProcessesChapter 3: Processes(3.1^ (3.

- 3.4 for now)-3.4 for now)

3.^

Chapter 3: Processes^ Chapter 3: Processes

!^ Process Concept!^ Process Scheduling!^ Operations on Processes!^ Cooperating Processes!^ Interprocess Communication!^ Communication in Client-Server Systems

3.^

Process in Memory^ Process in Memory

3.^

Process State^ Process State

!^ As a process executes, it changes

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

3.^

Process Control Block (PCB)^ Process Control Block (PCB)

Information associated with each process!^ Process state!^ Program counter!^ CPU registers!^ CPU scheduling information!^ Memory-management information!^ Accounting information!^ I/O status information

3.^

Process Control Block (PCB)^ Process Control Block (PCB)

3.^

Process Scheduling Queues^ 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

3.^

Ready Queue And Various I/O Device Queues^ Ready Queue And Various I/O Device Queues

3.^

Schedulers^ 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 allocatesCPU

3.^

Addition of Medium Term Scheduling^ Addition of Medium Term Scheduling

3.^

Context Switch^ Context Switch

!^ When CPU switches to another process, the system must save thestate of the old process and load the saved state for the newprocess!^ Context-switch time is overhead; the system does no useful workwhile switching!^ Time dependent on hardware support

3.^

Process Creation^ Process Creation

!^ Parent process create children processes, which, in turn createother processes, forming a tree of processes!^ Resource sharing^ "^

Parent and children share all resources " Children share subset of parent’s resources " Parent and child share no resources !^ Execution^ "^

Parent and children execute concurrently " Parent waits until children terminate

3.^

Process Creation^ Process Creation

3.^

C Program Forking Separate Process^ C Program Forking Separate Process

int main() { Pid_t pid;^ /* fork another process /^ pid = fork();^ 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 the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); } }