Docsity

Fundamentals of Operating Systems: Understanding Processes and Interprocess Communication , Study notes of Operating Systems

Partial preview of the text

Download Fundamentals of Operating Systems: Understanding Processes and Interprocess Communication and more Study notes Operating Systems in PDF only on Docsity!

Chapter 3: Processes

n What is a process?

n What is process scheduling?

n What are the common operations on processes?

n How to conduct process-level communication?

n How to conduct client-server communication?

Process Concept

n Process

l (^) is a program in execution l (^) is an instance of a computer program being sequentially executed l (^) process execution must progress in sequential fashion l (^) process is also called a job

n Program Vs. process

l (^) program is a passive entity; process is an active entity l (^) program only contains text; process is associated with code, data, PC, heap, stack, registers, and other information l (^) program becomes a process when an executable file is loaded into memory l (^) same program executed multiple times will correspond to different process each time

Process State

n During execution, the process may be in one of the following

states

l (^) new – process is being created l (^) running – instructions are being executed l (^) waiting – waiting for some event to occur l (^) ready – waiting to be assigned a processor l (^) terminated – process has finished execution

n Each processor can only run one process at a instant.

Diagram of Process State

Process Control Block (PCB) (2)

CPU Switch From Process to Process

Ready Queue And Various I/O Device Queues

Representation of Process Scheduling

Context Switch

n A context switch is the process of storing and restoring the

state (context) of the CPU such that multiple processes can

share a single CPU resource

l (^) for time-shared or multiprogramming environments l (^) context of a process represented in the PCB l (^) context switch involves a state save of the current process, and a state restore of the process being resumed next l (^) switch from user to kernel mode or vice-versa is a mode switch

n Context-switch time is overhead

l (^) the system does no useful work while switching l (^) overhead depends on hardware support  (^) Sun UltraSPARC provides multiple banks of registers  (^) Intel x86 processors also provide some support

Process Creation

n Any process can create other processes during its execution

l (^) operating systems have a primordial process l (^) creating process called parent process l (^) new process called child process l (^) processes identified and managed via a process identifier ( pid )

n Resource sharing options

l (^) parent and children share all resources l (^) children share subset of parent’s resources l (^) parent and child share no resources

n Execution options

l (^) parent and children execute concurrently l (^) parent waits until children terminate

Process Creation Example on Unix

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 Creation

n Parent waiting for child process to finish

Interprocess Communication

n Communication within the same system.

n Processes may need to co-operate for several reasons

l (^) information sharing l (^) computation speedup l (^) modularity l (^) convenience

n Cooperating process can affect or be affected by other

processes

l (^) typically, by sharing data

n Cooperating processes need interprocess communication

( IPC )

Producer-Consumer Problem

n Common paradigm for co-operating processes

l (^) producer process produces information l (^) consumer process consumes the produced information

n Processes need synchronization

l (^) consumer cannot use information before it is produced by the producer

n Abstraction models

l (^) unbounded-buffer places no practical limit on the size of the buffer l (^) bounded-buffer assumes that there is a fixed buffer size