CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.

Slides:



Advertisements
Similar presentations
Process Management.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
15-213, Fall 06 Outline Shell Lab Processes Signals.
1 Created by Another Process Reason: modeling concurrent sub-tasks Fetch large amount data from network and process them Two sub-tasks: fetching  processing.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
1 Processes Professor Jennifer Rexford
Processes CSCI 444/544 Operating Systems Fall 2008.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
CSSE Operating Systems
Process Description and Control A process is sometimes called a task, it is a program in execution.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Introduction to Processes CS Intoduction to Operating Systems.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Process. Processes A process is an abstraction for sequence of operations that implement a computation/program. A process may be manipulated, suspended,
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Creating and Executing Processes
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
CE Operating Systems Lecture 10 Processes and process management in Linux.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
System calls for Process management
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
System calls for Process management Process creation, termination, waiting.
1 Exceptional Control Flow Ⅱ. 2 Outline Kernel Mode and User Mode Process context switches Three States of Processes Context Switch System Calls and Error.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Process Management Process Concept Why only the global variables?
Using Processes.
Unix Process Management
UNIX PROCESSES.
Example questions… Can a shell kill itself? Can a shell within a shell kill the parent shell? What happens to background processes when you exit from.
Tarek Abdelzaher Vikram Adve Marco Caccamo
System Structure and Process Model
System Structure and Process Model
Processes in Unix, Linux, and Windows
Lecture 5: Process Creation
System Structure B. Ramamurthy.
LINUX System Programming with Processes (additional)
Cs561 Presenter: QIAOQIAO CHEN Spring 2012
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
Process Creation Process Termination
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CS510 Operating System Foundations
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
Process Description and Control in Unix
Chapter 3 Process Description and Control
Presentation transcript:

CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process Zombie process Lecture 141CS Operating Systems 1

Introduction to process management in UNIX What is a process? process is a unique instance of a running or runnable program Every process in Unix has these attributes  code: which denotes the task to be done  data: parameters to the code or other info about the process  stack: stack traces are useful to keep log of events or subroutine calls  a unique Process ID number (PID) When UNIX is started there's only one visible program called “init” with PID 1. Lecture 142CS Operating Systems 1

A UNIX process consists of... A unique identify (process id) A virtual address space Program code, program data in memory user/group identity, umask An execution environment, with attributes such as: – Environment variables, current working directory – List of open files – A description of actions to take on receiving signals Resource limits, scheduling priority and more… - See the exec() man page Lecture 143CS Operating Systems 1

Programs vs processes A program is the executable code A process is a running instance of a program More than one process can be concurrently executing the same program code — They will have separate execution resources — Different virtual address spaces, process id, etc. — On a modern OS - some execution resources will be shared if two processes are executing the same program code Lecture 144CS Operating Systems 1

Process management structure “init” is the ancestor of all the processes running in UNIX/Linux. Creation of new process happens in two phases — Phase 1: Duplication of parent process into two processes. — Phase 2: Replace the code of the child with that of another executable file. Parent and child process are virtually identical in Phase 1. All the code, data, stack info of the parent are copied to the child process. When a child process terminates, it notifies the parent so that it can take appropriate actions (Signal: SIGCHLD) Lecture 145CS Operating Systems 1

Important process states in UNIX Runnable Waiting for I/O, timer alarm, or signal - also known as "blocked" Waiting for CPU On the CPU Zombie Exited, waiting for parent to clean it up Running Waiting Lecture 146CS Operating Systems 1

How shell runs a utility Parent PID 34 Running shell Parent PID 34 Running shell Waiting for child Child PID 35 running shell Duplicate: fork() Child PID 35 running utility Differentiate: exec() Child PID 35 terminates Terminate: exit() Parent PID 34 running shell awakens Wait for child: wait() Signal: SIGCHLD Lecture 147CS Operating Systems 1

Creating a process fork() system call helps you to create a process manually. Prototype: int fork() — fork() returns the PID of the child process that is created from the parent. — Within the child process the fork() returns a 0. — If something went wrong, fork() returns -1 to the parent process and sets the global variable errno. If -1 is returned, then no child process was created Lecture 148CS Operating Systems 1

Fork() forms a family tree fork() Process - pid 3456 Process - pid 4578Process - pid 4583 fork() Process - pid 4800Process - pid 4807 fork() Lecture 149CS Operating Systems 1

getpid() and getppid() getpid() returns process id of a process. getppid() returns parent's process id. They always succeed. init() 's getppid() will return 1. Lecture 1410CS Operating Systems 1

Orphan process If a parent dies before its child process, the child is automatically adopted by the original init process. init Parent dies first Child survives the parent adopt child Lecture 1411CS Operating Systems 1

Terminating a process exit() is used to terminate a process at any time. Prototype: void exit(int status) closes all of a process's file descriptors, deallocates its code, data, and stack and then terminates the process. When a child process terminates it sends SIGCHLD signal and waits for its status code to be accepted by the parent. Lecture 1412CS Operating Systems 1

Zombie process A process that terminates cannot leave the system until its status code is accepted by its parent. If a parent is alive but never accepts the return code, the process will remain a zombie. A zombie process doesn't have any code, data or stack so it doesn't use up many system resources. Lecture 1413CS Operating Systems 1

Waiting for a process A parent waits for its child to terminate and then accepts its terminating code by executing wait() Prototype: pid_t wait(int *status) — A successful call returns the pid of the child that terminated and places a status code into status — If a process executes a wait() and has no children, it returns a -1. Lecture 1414CS Operating Systems 1

waitpid() Prototype: pid_t waitpid(pid_t pid, int *status, int options) — waits for a particular child process pid. — options < -1 - wait for any child process whose process group ID is equal to the absolute value of pid. — options = -1 meaning wait for any child process. — options = 0 meaning wait for any child process whose process group ID is equal to that of the calling process. — options > 0 meaning wait for the child whose process ID is equal to the value of pid. waitpid(-1, &status, 0) is same as wait(&status) Lecture 1415CS Operating Systems 1

Wait macros in sys/wait.h WIFEXITED(stat_val) Evaluates to a non-zero value if status was returned for a child process that terminated normally. WEXITSTATUS(stat_val) If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main(). WIFSIGNALED(stat_val) Evaluates to a non-zero value if status was returned for a child process that terminated due to the receipt of a signal that was not caught. WTERMSIG(stat_val) If the value of WIFSIGNALED(stat_val) is non-zero, this macro evaluates to the number of the signal that caused the termination of the child process. Lecture 14CS Operating Systems 116

More macros in sys/wait.h WIFSTOPPED(stat_val) Evaluates to a non-zero value if status was returned for a child process that is currently stopped. WSTOPSIG(stat_val) If the value of WIFSTOPPED(stat_val) is non-zero, this macro evaluates to the number of the signal that caused the child process to stop. WIFCONTINUED(stat_val) Evaluates to a non-zero value if status was returned for a child process that has continued from a job control stop. Lecture 14CS Operating Systems 117