Process Management and Interprocess Communication in Operating Systems, Slides of Computer Science

The concept of a process in operating systems, including its organization in memory, state, context, and control block (pcb). It also discusses process creation, termination, and switching, as well as interprocess communication methods such as message passing, mailboxes, and remote procedure calls.

Typology: Slides

2012/2013

Uploaded on 03/27/2013

ekana
ekana 🇮🇳

4

(44)

370 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Chapter 3: Processes
A primary task of an operating system is to
execute & manage processes
Process management
Issue with multiprogrammed systems, and multi-
tasking systems
May not be an issue with some systems (e.g., embedded
systems– why?)
Terms
Process organization in memory
Text section (program code)
Data section: including stack & heap
Process state
Process context
Process control block (PCB)
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

Partial preview of the text

Download Process Management and Interprocess Communication in Operating Systems and more Slides Computer Science in PDF only on Docsity!

1

Chapter 3: Processes

  • A primary task of an operating system is to

execute & manage processes

  • Process management
    • Issue with multiprogrammed systems, and multi- tasking systems
    • May not be an issue with some systems (e.g., embedded systems– why?)
  • Terms
    • Process organization in memory
      • Text section (program code)
      • Data section: including stack & heap
    • Process state
    • Process context
    • Process control block (PCB)

2

What is a process?

  • More than a program
    • A process is a program in execution (Ch 1, p.
  • A program plus all the OS data structures

needed to run it

4

Process “State”

  • As a process is running it changes state
  • State: Indicates the current activity (or life

phase) of a process.

5

Diagram of Process State

(Figure 3.2, p. 101) Docsity.com

7

Process Control Block (PCB)

  • Each process has a PCB
    • Maintains context for the process when it’s not running
    • Also stores other information for process
    • Contents may vary by process type (e.g., threads, tasks)
  • What is the context of a process?
    • Context : When a process “looses” the CPU, what needs to be saved so that the process can be resumed later?
    • Must save info including:
      • CPU registers, memory management info
    • Context is also referred to as “state”, which is confusing!

8

process context

In what address space are PCB’s stored?

What is this?

Also: Process priority

10

Switching Between Processes

(a) save context of current process

  • Context of current process saved to PCB for that process
  • Includes: (a) CPU register values: instruction counter, stack pointer, data registers, status register, and (b) memory management information

(b) load the context of the “next” process

  • Context loaded from the PCB for the process
  • Includes: (a) CPU register values: instruction counter, stack pointer, data registers, status register, and (b) memory management information

Linux process switch code (pp. 383-394, Linux scheduler, "The Linux Kernel Primer"; Handout) Docsity.com

11

Diagram Showing CPU Switch

From Process to Process (Fig 3.4)

right word?

right word?

How should we organize the

PCB’s for the processes?

  • We have multiple PCB’s– need some kind

of data structure to organize them

  • Typically, in a collection of queues

13

14

PCB Queues (Fig 3.6)

Note the names

Creating Processes (“Heavy

Weight Processes”)

  • Terms
    • Parent : Process that creates a new process
    • Child : the new process that is created
  • Processes have unique identifiers
    • Often an integer value, process identifier (pid)
    • Often, parent obtains child pid when creating a child
  • With multiple processes
    • Introduces coordination & synchronization issues
    • E.g., how do processes share data?
  • Different methods of starting a child process
    • E.g.,
      • Child runs a new program, or
      • Child runs same program
        • Make copy of all or parts of parents address space (e.g., UNIX)Docsity.com

17

Starting a Process on UNIX

  • System call:

int fork(); // returns child pid in parent

  • Creates a new process, the child
  • Child process gets a copy of parent address space
  • fork() system call has unusual semantics
  • fork() call returns twice!
    • Once in address space of child process
      • Function return value is 0 in child
    • Once in address space of parent process
      • Function return value is process ID of child in parent

19

Figure 3.11: Process creation

(One pattern of usage: exec is optional and waiting for child to die is optional)

20

#include <stdio.h> /* Example of creating a new process on UNIX (BSD; OS X) */ #include <sys/types.h> #include <unistd.h> #include <sys/wait.h>

int a = 1;

int main() { int status; int pid = fork(); if (-1 == pid) { printf("Eror calling fork\n"); } else if (0 == pid) { /* in child process / printf("Press enter to continue in child...\n"); fflush(stdout); getchar(); a = 10; // return from child, and terminate } else { / in parent process */ printf("Value of 'a' before waiting for child= %d\n", a); wait(&status); // status will have pid of child printf("Value of 'a' after waiting for child= %d\n", a); fflush(stdout); } }

OUTPUT: Value of 'a' before waiting for child= 1 Press enter to continue in child... Value of 'a' after waiting for child= 1

Docsity.com