chapter 3 process description and control• a description of the parameters passed to readfile()...
Post on 26-Jun-2020
9 Views
Preview:
TRANSCRIPT
Chapter 3Process Description
and ControlSeventh Edition
By William Stallings
Operating Systems:Internals
and Design
Principles
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
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
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
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)
PCB (Summary)
ØIDØState informationq SPq General Purpose Registersq PCq PSW
ØControl Informationq Open Filesq Allocated Memoryq Data Structuresq I/Oq Scheduling
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
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);
}}
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);}
Process model with 2 suspended states
Process model with 2 suspended states
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
How to do SWITCH???
1.Mode Switch2.Context Switch3.Process Switch
Types of Kernel
Non-Process Kernel
Exe within User-process
Process –based Kernel
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
top related