Slide 1Slide 2Traditional UNIX System StructureSystem CallAPI – System Call – Operating system RelationshipStandard C Library ExampleWhat is a process?Process in MemoryProcess controlProcess control (contd.)Process Creation (contd.)Process Creation (Contd.)Process Creation (contd.)A five-state process modelState Transition DiagramProcess creation - ExampleSystem Calls For Process Management and File ManagementB I N A R A M A M U R T H YB I N A @ B U F FA L O. E D UU N I V E R S I T Y AT B U F FA L OSystem Structure and Process Model01/13/20191Traditional unix structureSystem callStandard C libraries01/13/20192Page 3Traditional UNIX System Structure01/13/201901/13/20194System Call There are 11 steps in making the system call read (fd, buffer, nbytes)Page 5API – System Call – Operating system Relationship01/13/2019Page 6Standard C Library ExampleC program invoking printf() library call, which calls write() system call01/13/2019Page 7What is a process?A process is simply a program in execution: an instance of a program execution.Unit of work individually schedulable by an operating system (OS).A process includes:program counter stackdata sectionOS keeps track of all the active processes and allocates system resources to them according to policies devised to meet design performance objectives.To meet process requirements OS must maintain many data structures efficiently.The process abstraction is a fundamental OS means for management of concurrent program execution. Example: instances of process co-existing.01/13/2019Page 8Process in Memory01/13/2019Page 9Process controlProcess creation in unix is by means of the system call fork(). OS in response to a fork() call:Allocate slot in the process table for new process.Assigns unique pid to the new process..Makes a copy of the process image, except for the shared memory.both child and parent are executing the same code following fork()Move child process to Ready queue. it returns pid of the child to the parent, and a zero value to the child.01/13/2019Page 10Process control (contd.)All the above are done in the kernel mode in the process context. When the kernel completes these it does one of the following as a part of the dispatcher:Stay in the parent process. Control returns to the user mode at the point of the fork call of the parent.Transfer control to the child process. The child process begins executing at the same point in the code as the parent, at the return from the fork call.Transfer control another process leaving both parent and child in the Ready state.01/13/2019Page 11Process Creation (contd.)Parent process create children processes, which, in turn create other processes, forming a tree of processesGenerally, process identified and managed via a process identifier (pid)Resource sharingParent and children share all resourcesChildren share subset of parent’s resourcesParent and child share no resourcesExecutionParent and children execute concurrentlyParent waits until children terminate01/13/2019Page 12Process Creation (Contd.)Address spaceChild duplicate of parentChild has a program loaded into itUNIX examplesfork system call creates new processexec system call used after a fork to replace the process’ memory space with a new program01/13/2019Page 13Process Creation (contd.)01/13/2019Page 14A five-state process modelFive states: New, Ready, Running, Blocked, ExitNew : A process has been created but has not yet been admitted to the pool of executable processes.Ready : Processes that are prepared to run if given an opportunity. That is, they are not waiting on anything except the CPU availability.Running: The process that is currently being executed. (Assume single processor for simplicity.)Blocked : A process that cannot execute until a specified event such as an IO completion occurs.Exit: A process that has been released by OS either after normal termination or after abnormal termination (error).01/13/2019Page 15State Transition Diagram NEWREADYRUNN INGBLOCKEDEXITAdmitDispatchTime-outReleaseEvent WaitEvent OccursThink of the conditions under which state transitions may take place.01/13/2019Page 16Process creation - Examplemain () { int pid; cout << “ just one process so far”<<endl; pid = fork(); if (pid == 0) cout <<“I am the child “<< endl; else if (pid > 0) cout <<“I am the parent”<< endl; else cout << “fork failed”<< endl;}01/13/201901/13/201917System Calls For Process Management and File
View Full Document