CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes.

Slides:



Advertisements
Similar presentations
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.
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.
CS591 (Spring 2001) The Linux Kernel: Process Management.
Processes CSCI 444/544 Operating Systems Fall 2008.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Introduction to Kernel
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.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
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.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
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.
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.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Operating Systems CMPSC 473 Processes (4) September Lecture 10 Instructor: Bhuvan Urgaonkar.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
Linux Processes. Process Descriptor Process – dynamic, program in motion –Kernel data structures to maintain "state" –Descriptor, PCB (control block),
Threads G.Anuradha (Reference : William Stallings)
System calls for Process management
1 Chapter 4 Processes R. C. Chang. 2 Linux Processes n Each process is represented by a task_struct data structure (task and process are terms that Linux.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CSC 660: Advanced Operating Systems
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
What is a Process ? A program in execution.
System calls for Process management Process creation, termination, waiting.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Processes David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
CS703 – Advanced Operating Systems By Mr. Farhan Zaidi.
Introduction to Kernel
Processes and threads.
Process Management Process Concept Why only the global variables?
Unix Process Management
Processes David Ferry, Chris Gill
Processes A process is a running program.
Processes in Unix, Linux, and Windows
Structure of Processes
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Processes (Ch 4.1).
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
Process Description and Control in Unix
Process Description and Control in Unix
Processes David Ferry, Chris Gill, Brian Kocoloski
Structure of Processes
Presentation transcript:

CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes

CSC 660: Advanced Operating SystemsSlide #2 Topics 1.What is a Process? 2.Task Descriptor 3.Process Lifecycle 4.Process Address Space 5.Context Switch 6.Linked lists 7.Creation 8.fork() and clone() 9.Process Relationships 10.Termination 11.Zombies

CSC 660: Advanced Operating SystemsSlide #3 What is a process? A process is a program in execution. Program code + dynamic execution context. Virtualization Processes provide virtual CPU + virtual memory. Kernel refers to processes as tasks.

CSC 660: Advanced Operating SystemsSlide #4 What is in a process? A process consists of. Program code. Address space. Data. Resources: open files, signals. At least one thread of execution. Threads contain: Program counter. Stack. Register set.

CSC 660: Advanced Operating SystemsSlide #5 Process Control Block: task_struct

CSC 660: Advanced Operating SystemsSlide #6 Process Identity Kernel: Address of task_struct –current macro User space: PID –current->pid –32768 possible PIDs –pidhash

CSC 660: Advanced Operating SystemsSlide #7 Process Lifecycle

CSC 660: Advanced Operating SystemsSlide #8 Process State TASK_RUNNING Process is ready or running. TASK_INTERRUPTIBLE Waiting, able to receive interrupts. TASK_UNINTERRUPTIBLE Waiting, unable to receive interrupts. TASK_STOPPED Execution stopped, can resume with SIGCONT. TASK_TRACED Execution stopped by the ptrace() debugging mechanism. EXIT_ZOMBIE Execution terminated, but parent hasn’t wait() ed. EXIT_DEAD Being removed from system as parent has wait() ed.

CSC 660: Advanced Operating SystemsSlide #9 Process Address Space Process appears to have flat memory space. Discontinguous areas of physical memory mapped via page table to produce virtual memory. Described by mm_struct Virtual memory space 3GB virtual memory on 32-bit architectures. High 1GB reserved for mapping kernel memory.

CSC 660: Advanced Operating SystemsSlide #10 32-bit Process Address Space 0x xBFFFFFFF text data heap stack EIP ESP bss

CSC 660: Advanced Operating SystemsSlide #11 Context Switch When does scheduler switch out process? Blocked on I/O. Time slice expires. Where is switching done? In schedule() function. How does it switch? Switch to new page table. Save hardware context to stack. Switch stack pointers. Load hardware context of next process from stack.

CSC 660: Advanced Operating SystemsSlide #12 Context Switch Example

CSC 660: Advanced Operating SystemsSlide #13 Your own task_struct How to find your task_struct ? 1. stack pointer points to top of kernel stack 2. thread_info stored at bottom of kernel stack 3. mask 13 lsb’s of stack pointer to get address 4. thread_info has pointer to task_struct Use current macro to do this normally.

CSC 660: Advanced Operating SystemsSlide #14 Your own task_struct

CSC 660: Advanced Operating SystemsSlide #15 Kernel linked lists Circular doubly-linked list. No special first or last node. Defined in struct list_head { struct list_head *next, *prev; } Use by embedding in structures: struct my_struct { struct list_head list; void *data; }

CSC 660: Advanced Operating SystemsSlide #16 Kernel linked lists

CSC 660: Advanced Operating SystemsSlide #17 Kernel Linked Lists struct my_struct *p; struct list_head *new, *x, *my; INIT_LIST_HEAD(&p->list) Create a new linked list of my_struct’s. list_add(new, p) Add new list_head to list after p. list_del(struct list_head *x) Remove structure containing list_head pointer x. list_for_each(p, &my->list) Iterate over list starting with my, with p as pointer to current element. list_entry(p, struct my_struct, list) Return pointer to my_struct whose list_head is p.

CSC 660: Advanced Operating SystemsSlide #18 Process Lists #define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks) #define prev_task(p) list_entry((p)->tasks.prev, struct task_struct, tasks) #define for_each_process(p) \ for (p = &init_task ; (p = next_task(p)) != &init_task ; )

CSC 660: Advanced Operating SystemsSlide #19 Where do processes come from? Kernel creates some processes. Kernel threads. init Processes create all other processes. Process copies itself with fork(). Original is parent, new process is child. Child can load its own program with exec().

CSC 660: Advanced Operating SystemsSlide #20 Process Creation and Termination

CSC 660: Advanced Operating SystemsSlide #21 fork() System call creates a new process Creates a new task_struct. Initializes with copy of parent resources. Creates a new address space. Page table is copy-on-write pointer to parent. Places child process on ready queue. Returns in both parent and child. Parent return value is PID of child process. Error return value of -1 indicates no child. Child return value is 0.

CSC 660: Advanced Operating SystemsSlide #22 clone() Threads are just a type of process. Share address space, files, signal handlers. All processes/threads created by clone() Process: clone(SIGCHLD, 0) Thread: clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);

CSC 660: Advanced Operating SystemsSlide #23 Process Relationships real_parent Process that created p or process 1 ( init ). parent Process to be signaled on termination. If ptrace(), is debugging process, else real_parent. children List of all children created by p. sibling Pointers to next and previous elements of sibling list.

CSC 660: Advanced Operating SystemsSlide #24 Process Relationships

CSC 660: Advanced Operating SystemsSlide #25 Process Tree (Solaris)

CSC 660: Advanced Operating SystemsSlide #26 Process Termination Voluntary exit() system call. C compiler automatically adds to binaries. Involuntary signal exception

CSC 660: Advanced Operating SystemsSlide #27 Signals Software interrupts used for asynchronous communiction between processes. –SIGALRM: alarm() timer has gone off. –SIGINT: interrupt signal generated by Ctrl-c. –SIGSEGV: segmentation violation sent by kernel when process accesses invalid address. –SIGKILL: terminates a process. Process can either –Ignore the signal: SIGKILL/STOP cannot be ignored. –Catch the signal: Create a signal handler function and register it with the kernel to be called on signal.

CSC 660: Advanced Operating SystemsSlide #28 do_exit() 1.Sets PF_EXITING flag. 2.Releases resources: 1.Address space. 2.File handles. 3.Signal handlers and timers. 3.Sets exit_code member of task_struct. 4.Notifies parent of termination ( SIGCHLD ) 5.Reparents any children of process. 6.Set process state to EXIT_ZOMBIE. 7.Calls schedule() to switch to new process.

CSC 660: Advanced Operating SystemsSlide #29 The Undead Why do we need zombies? Must keep task_struct so parents can get exit_code member. Parent issues wait() system call to get exit. If parent predeceases child, init will be parent. Calls release_task() to free resources. Removes process from lists, hashes, caches. Frees kernel stack and thread_info struct. Frees task_struct.

CSC 660: Advanced Operating SystemsSlide #30 Kernel Threads System processes that run only in kernel mode –Use kernel page tables (mem > PAGE_OFFSET ) –Created by kernel_thread() function which calls do_fork(flags|CLONE_VM|CLONE_UNTRACED,…) Process 0: swapper –The idle process, runs cpu_idle() when no other processes in TASK_RUNNING state. –Created statically when kernel boots. Process 1: init –Created by process 0 via kernel_thread(). –Uses execve() system call to load init program.

CSC 660: Advanced Operating SystemsSlide #31 Logging In login program 1.Checks password. 2.chdir to homedir. 3.chown terminal to user. 4.sets group IDs 5.initializes env variables 6.changes UID to user 7.execs login shell

CSC 660: Advanced Operating SystemsSlide #32 Key Points Process = program + execution context Execution context stored in PCB ( task_struct.) –Tasks organized in a doubly linked list. –Referenced by PID from user space. –Process states: RUNNING, (UN)INTERRUPTIBLE Process provides virtual CPU + memory. Scheduler manages context switches. Processes and threads created by clone(). –Parent/child and sibling relationships. –Kernel reclaims resources on exit().

CSC 660: Advanced Operating SystemsSlide #33 References 1.Daniel P. Bovet and Marco Cesati, Understanding the Linux Kernel, 3 rd edition, O’Reilly, Robert Love, Linux Kernel Development, 2 nd edition, Prentice-Hall, Claudia Rodriguez et al, The Linux Kernel Primer, Prentice-Hall, Peter Salzman et. al., Linux Kernel Module Programming Guide, version 2.6.1, Avi Silberchatz et. al., Operating System Concepts, 7 th edition, W. Richard Stevens and Stephen Rago, Advanced Programming in the UNIX Environment, 2 nd edition, Andrew S. Tanenbaum, Modern Operating Systems, 3 nd edition, Prentice-Hall, 2005.