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.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

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
The Process Model.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Understand Process concept Process scheduling Creating.
Processes CSCI 444/544 Operating Systems Fall 2008.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Unix Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CMPT 300: Operating Systems I Ch 3: Processes Dr. Mohamed Hefeeda
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Process Concept An operating system executes a variety of programs
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Introduction to Processes CS Intoduction to Operating Systems.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Processes: program + execution state
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Process Management Jerrod Howlett Sarah Sullivan.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
CSC 660: Advanced Operating Systems
Lecture 4: Processes & Threads. Lecture 4 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The concept of Process Process states and life-cycle.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 8 Processes II Read Ch.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Lecture 3 Process.
Chapter 3: Processes.
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also.
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process Concept
Chapter 3: Processes.
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 2: Processes Part 1
System Structure B. Ramamurthy.
CGS 3763 Operating Systems Concepts Spring 2013
System Structure and Process Model
Operating Systems Lecture 6.
CGS 3763 Operating Systems Concepts Spring 2013
Process & its States Lecture 5.
Chapter 3: Processes.
Operating System Concepts
Process Creation Process Termination
Unix Process Elements Reading Reference: Textbook: Chapter 3
Chapter 3: Processes.
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

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

A Process In Memory Stack: –Local variables declared inside functions –Function Parameters Heap: –Dynamically allocated memory Data: –Global variables, etc. Text: –Program Instructions

Process State As a process executes, it changes state –TASK_RUNNING: Task is either running or on a runqueue waiting to run. –TASK_INTERRUPTIBLE: The process is waiting for some event to occur. Becomes running when event occurs. –TASK_UNINTERRUPTIBLE: Identical to TASK_INTERRUPTIBLE except it does not wake up and become runnable if it receives a signal. Used rarely. –TASK_ZOMBIE: The task has been terminated, but its parent has not yet issued a wait4() system call. The task's process descriptor must remain in case the parent wants to access it. If parent calls wait4(), descriptor is deallocated. –TASK_STOPPED: Process execution has stopped; the task is not running nor is it eligible to run.

Family Hierarchy All processes are born from a parent, and all have 0 or more children. If the parent of a process dies, it becomes an orphan. The process is then adopted by the init process (PID 1). When a process dies, but is still in the queue, it is a zombie process.

Process Control Block (PCB) Information from various process is stored here, also known as the task_struct: –Process state –Program counter –CPU registers –CPU scheduling information –Memory-management information –Accounting information –I/O status information

PCB diagram

pt_regs Registers are actually stored in a struct called pt_regs. This is an architecture-specific data structure.

CPU Switch From Process to Process

Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support

Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes Resource sharing –Parent and children share all resources –Children share subset of parent’s resources –Parent and child share no resources Execution –Parent and children execute concurrently –Parent waits until children terminate

Process Creation (Cont.) Address space –Child duplicate of parent –Child has a program loaded into it UNIX examples –fork system call creates new process –exec system call used after a fork to replace the process’ memory space with a new program

Process Creation

Copy-on-Write Copy-on-write is a technique that prevents copying all the data when a new process is born. Parent and child processes share a single copy of the data. If any of the data is written to, it is marked and then a duplicate is made; each process receives its own unique copy. Linux implements fork() via the clone() system call. The bulk of the work is done in do_fork(), which calls copy_process(), then the process starts running.

copy_process() Calls dup_task_struct(), which creates a new kernel stack, thread_info structure, and task_struct for the new process. Checks that new child will not exceed the resource limits on number of processes for the current user. The child's state is set to TASK_UNINTERRUPTIBLE, to ensure that it does not yet run. Calls copy_flags() to update the flags member of the task_struct. The PF_SUPERPRIV flag, which denotes whether a task used super-user privileges, is cleared. The PF_FORKNOEXEC flag, which denotes a process that has not called exec(), is set. Now the child needs to differentiate itself from its parent. Various members of the process descriptor are cleared or set to initial values. Members of the process descriptor that are not inherited are primarily statistically information. The bulk of the data in the process descriptor is shared.

copy_process() (cont'd) Next, it calls get_pid() to assign an available PID to the new task Depending on the flags passed to clone(), copy_process() then either duplicates or shares open files, filesystem information, signal handlers, process address space, and namespace. These resources are typically shared between threads in a given process; otherwise they are unique and copied here. The remaining timeslice between the parent and child is split between the two. Finally, copy_process() cleans up and returns to the caller a pointer to the new child

C Program Forking Separate Process 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); }

A tree of processes on a typical Solaris

Process Termination Process executes last statement and asks the operating system to delete it (exit) –Output data from child to parent (via wait) –Process’ resources are deallocated by operating system Parent may terminate execution of children processes (abort) –Child has exceeded allocated resources –Task assigned to child is no longer required –If parent is exiting Some operating system do not allow child to continue if its parent terminates –All children terminated - cascading termination

EXAM! What are the five states a process can be in? Label the ps -ef columns. What happens to a Linux process when its parents die?

References CS430 Class slides Love, Robert. Linux Kernel Development. Second edition.