Process Description and Control in Unix

Slides:



Advertisements
Similar presentations
Process Description and Control
Advertisements

Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chapter 3 Process Description and Control
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Introduction to Processes
Process Description and Control
The Process Model.
1 Process Description and Control Module When to Switch a Process ? n A process switch may occur whenever the OS has gained control of CPU. ie.
Unix Processes.
Structure of Processes
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
UNIX Process Creation Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Phones OFF Please Processes Parminder Singh Kang Home:
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process Description and Control
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
Chapter 3 Process Description and Control
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Threads G.Anuradha (Reference : William Stallings)
System calls for Process management
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
System calls for Process management Process creation, termination, waiting.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Introduction to Kernel
Process Management Process Concept Why only the global variables?
Protection of System Resources
Unix Process Management
Processes in Unix, Linux, and Windows
System Structure and Process Model
System Structure and Process Model
Structure of Processes
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Process & its States Lecture 5.
Mid Term review CSC345.
Process Description and Control
Process Description and Control
Process Description and Control
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Process Description and Control
Process Description and Control
Process Description and Control in Unix
Structure of Processes
Presentation transcript:

Process Description and Control in Unix B. Ramamurthy Fall 2006 5/14/2019

Creation of a process A unique pid is assigned to the new process. Space is allocated for all the elements of the process image. The process control block is initialized. Inherit info from parent. The appropriate linkages are set: for scheduling, state queues.. Create and initialize other data structures (file tables, IO table etc.). 5/14/2019

Process Interruption Two kinds of process interruptions: interrupt and trap. Interrupt: Caused by some event external to and asynchronous to the currently running process, such as completion of IO. Trap : Error or exception condition generated within the currently running process. Ex: illegal access to a file, arithmetic exception. (supervisor call) : explicit interruption. 5/14/2019

Unix system V All user processes in the system have as root ancestor a process called init. When a new interactive user logs onto the system, init creates a user process, subsequently this user process can create child processes and so on. init is created at the boot-time. Process states : User running , kernel running, Ready in memory, sleeping in memory (blocked), Ready swapped (ready-suspended), sleeping swapped (blocked-suspended), created (new), zombie , preempted (used in real-time scheduling). 5/14/2019

UNIX SVR4 Process States Similar to our 7 state model 2 running states: User and Kernel transitions to other states (blocked, ready) must come from kernel running Sleeping states (in memory, or swapped) correspond to our blocking states A preempted state is distinguished from the ready state (but they form 1 queue) Preemption can occur only when a process is about to move from kernel to user mode 5/14/2019

UNIX Process State Diagram 5/14/2019

Process and kernel context process context system calls Application pgms Kernel acts on behalf of user User mode kernel mode kernel tasks interrupt services kernel context 5/14/2019

Unix system V (contd.) What does unix process image contain? What does process table entry contain? proc What is unix U (user) area? u area Function of each of these components. 5/14/2019

U area Process control block Pointer to proc structure (process table entry) Signal handlers related information Memory management information Open file descriptor Vnodes(?) of the current directory CPU usage stats Per process kernel stack 5/14/2019

Process Context User address space, Control information : u area (accessed only by the running process) and process table entry (or proc area, accessed by the kernel) Credentials : UID, GID etc. Environment variables : inherited from the parent 5/14/2019

UNIX Process Image User-level context Register context Process Text (ie: code: read-only) Process Data User Stack (calls/returns in user mode) Shared memory (for IPC) only one physical copy exists but, with virtual memory, it appears as it is in the process’s address space Register context 5/14/2019

UNIX Process Image System-level context Process table entry the actual entry concerning this process in the Process Table maintained by OS Process state, UID, PID, priority, event awaiting, signals sent, pointers to memory holding text, data... U (user) area additional process info needed by the kernel when executing in the context of this process effective UID, timers, limit fields, files in use ... Kernel stack (calls/returns in kernel mode) Per Process Region Table (used by memory manager) 5/14/2019

Process images in virtual memory 5/14/2019

Process control Process 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. Makes a copy of the process image, except for the shared memory. Move child process to Ready queue. it returns pid of the child to the parent, and a zero value to the child. 5/14/2019

Process 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. 5/14/2019

UNIX Process Creation Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique PID to the child process child gets a copy of process image of parent: both child and parent are executing the same code following fork() but fork() returns the PID of the child to the parent process and returns 0 to the child process 5/14/2019

Process creation - Example main () { 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;} 5/14/2019

fork and exec Child process may choose to execute some other program than the parent by using exec call. Exec overlays a new program on the existing process. Child will not return to the old program unless exec fails. This is an important point to remember. Why does fork need to clone? Why do we need to separate fork and exec? Why can’t we have a single call that fork a new program? 5/14/2019

Example if (( result = fork()) == 0 ) { // child code if (execv (“new program”,..) < 0) perror (“execv failed “); exit(1); } else if (result < 0 ) perror (“fork”); …} /* parent code */ 5/14/2019

Version of exec Many versions of exec are offered by C library: exece, execve, execvp,execl, execle, execlp We will look at these and methods to synchronize among various processes (wait, signal, exit etc.). 5/14/2019