chapter 3 process description and control• a description of the parameters passed to readfile()...

19
Chapter 3 Process Description and Control Seventh Edition By William Stallings Operating Systems: Internals and Design Principles

Upload: others

Post on 26-Jun-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Chapter 3Process Description

and ControlSeventh Edition

By William Stallings

Operating Systems:Internals

and Design

Principles

Page 2: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Example of Standard API

• Consider the ReadFile() function in the• Win32 API—a function for reading from a file

• A description of the parameters passed to ReadFile()– HANDLE file—the file to be read– LPVOID buffer—a buffer where the data will be read into and written from– DWORD bytesToRead—the number of bytes to be read into the buffer– LPDWORD bytesRead—the number of bytes read during the last read– LPOVERLAPPED ovl—indicates if overlapped I/O is being used

Page 5: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Micro-Kernel•In the mid 1980s, researchers at Carnegie Mellon developed the

Mach microkernel OS•Moves nonessential components from the kernel into “user” spaceresulting in a smaller kernel

•Main function of the microkernel is to provide a communication facility between the client program and various services that are also running in user spaceo Communication takes place between user modules using message passing.

Benefits:Øeasier to extend a microkernel

o all new services are added to user spaceØeasier to port the operating system to new architecturesØmore reliable and secure

o less code is running in kernel mode

Page 6: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Process

A process (sometimes called a task, or a job) is, informally, a program in execution

Everything necessary to resume theprocess’ execution if it is somehow put aside temporarily

Page 7: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

PCB

For every process, the OS maintains a Process Control Block (PCB), a datastructure that represents the process and its state.Process id numberØ User-id of ownerØ Memory space (static, dynamic)Ø Program Counter, Stack Pointer, general purpose registersØ Process state (running, not-running, etc.)Ø CPU scheduling information (e.g., priority)Ø List of open filesØ I/O states, I/O in progressØ Pointers into CPU scheduler’s state queues (e.g., the waiting queue)

Page 11: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

PCB (Summary)

ØIDØState informationq SPq General Purpose Registersq PCq PSW

ØControl Informationq Open Filesq Allocated Memoryq Data Structuresq I/Oq Scheduling

Page 12: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Operating System Role in Process Management

Operating System Role in Process Management

The operating system is responsible for the following activities in connection with process management.

ØProcess creation and deletion.

ØProcess suspension and resumption.

ØProvision of mechanisms for:•process synchronization•process communication

Page 13: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

UNIX Process Creationint 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);

}}

Page 14: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Windows Process Creation#include <stdio.h>#include <windows.h>

int main (VOID){STARTUPINFO si;PROCESS_INFORMATION pi;

//allocates memoryZeroMemory(&si, sizeof(si));si.cb = sizeof(si);ZeroMemory(&pi, sizeof(pi));//create child processIf (!CreateProcess(NULL,“C:\\WINDOWS\system32\\mspaint.exe”,NULL,NULL,FALSE,0,

NULL, NULL,&si, &pi)){ fprint(stderr,”Create Process Failed”); return -1; }

//parent will wait for the child to completeWaitForSingleObject(pi.hProcess, INFINITE);Printf(“Child Complete”);

//close handlesCloseHandle(pi.hProcess); CloseHandle(pi.hThread);}

Page 15: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Process model with 2 suspended states

Process model with 2 suspended states

Page 16: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Structure of Process Structure of Process Images in Virtual MemoryImages in Virtual Memory

Structure of Process Structure of Process Images in Virtual MemoryImages in Virtual Memory

Page 17: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

How to do SWITCH???

1.Mode Switch2.Context Switch3.Process Switch

Page 18: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

Types of Kernel

Non-Process Kernel

Exe within User-process

Process –based Kernel

Page 19: Chapter 3 Process Description and Control• A description of the parameters passed to ReadFile() ... For every process, the OS maintains a Process Control Block (PCB), a data structure

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 via parallel sub-tasks– Modularity by dividing system functions into separate

processes – Convenience - even an individual may want to edit,

print and compile in parallel