Operating Systems: Internals and Design Principles Chapter 3 Process Description and Control Seventh Edition By William Stallings
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
Traditional UNIX Systems
Micro-Kernel
Micro-Kernel In the mid 1980s, researchers at Carnegie Mellon developed the Mach microkernel OS Moves nonessential components from the kernel into user space resulting 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 space o 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 the process execution if it is somehow put aside temporarily
PCB For every process, the OS maintains a Process Control Block (PCB), a data structure 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)
Process Control Block
Control Tables
PCB
PCB (Summary) ID State information SP General Purpose Registers PC PSW Control Information Open Files Allocated Memory Data Structures I/O Scheduling
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 Creation 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); } }
#include <stdio.h> #include <windows.h> int main (VOID) { STARTUPINFO si; PROCESS_INFORMATION pi; Windows Process Creation //allocates memory ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); //create child process If (!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 complete WaitForSingleObject(pi.hProcess, INFINITE); Printf( Child Complete ); //close handles CloseHandle(pi.hProcess); CloseHandle(pi.hThread); }
Process model with 2 suspended states
Structure of Process Images in Virtual Memory
How to do SWITCH??? 1.Mode Switch 2.Context Switch 3.Process Switch
Non-Process Kernel Types of Exe within Userprocess Kernel 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