Processes: Concept, Scheduling, Interprocess Communication and Cooperation, Slides of Computer Science

An overview of processes, including their concept, scheduling, interprocess communication, and cooperation. Topics covered include process states, process control blocks, process scheduling queues, context switching, process creation, process synchronization, and process termination. The document also discusses various communication models, such as message passing and shared memory, and their implementation.

Typology: Slides

2012/2013

Uploaded on 03/28/2013

ekana
ekana 🇮🇳

4

(44)

370 documents

1 / 52

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Processes
Chapter 3
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34

Partial preview of the text

Download Processes: Concept, Scheduling, Interprocess Communication and Cooperation and more Slides Computer Science in PDF only on Docsity!

Processes

Chapter 3

Processes

• Process Concept

• Process Scheduling

• Operations on Processes

• Cooperating Processes

• Interprocess Communication

• Communication in Client-Server Systems

Process in Memory

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 processor
    • terminated : The process has finished execution

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

Representation of Process Scheduling

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
  • 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

CPU Switch From Process to Process

Process Creation

  • Parent process create children processes, which, in turn

create other 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
  • Address space
    • Child duplicate of parent
    • Child has a program loaded into it

Process Creation (Cont.)

  • 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

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); } }

Process synchronization

  • The parent can wait for a child to terminate using the wait( ) function. int cpid_done, status; cpid_done = wait(&status);
  • The caller sleeps until any child terminates.
  • cpid_done gets the pid of the child that terminated.
  • status gets the exit status of the terminated process.

int cpid_done, status, options = 0; cpid_done = waitpid(cpid, &status, options);

  • caller sleeps until child with cpid terminates.
  • returns the pid of the terminating child
  • stores the status of the terminating child in status.

Basic Shell code

Pseudo-code a basic shell (not real C++ code):

while (1) { parse_command_line; (get command, args, redirect, etc.) if(cmd == exit) exit; p = fork( ); if (p == 0) { exec (cmd, args) } else { if (command doesn't end with &) wait( ); } }

Cooperating Processes

• Independent process cannot affect or be

affected by the execution of another process

• Cooperating process can affect or be affected

by the execution of another process

• Advantages of process cooperation

  • Information sharing
  • Computation speed-up
  • Modularity
  • Convenience