Linux kernel internals Introduction to process descriptors.

Slides:



Advertisements
Similar presentations
Process Management.
Advertisements

Linked Lists Linked Lists Representation Traversing a Linked List
The University of Adelaide, School of Computer Science
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Context Switch Animation Another one by Anastasia.
Processes CSCI 444/544 Operating Systems Fall 2008.
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
Introduction to Kernel
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
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.
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.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Introduction to Processes CS Intoduction to Operating Systems.
Implementing Processes and Process Management Brian Bershad.
Runtime Environments Compiler Construction Chapter 7.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
1 Linux Operating System 許 富 皓. 2 Processes Switch.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
Operating Systems CMPSC 473 Processes (4) September Lecture 10 Instructor: Bhuvan Urgaonkar.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
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.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
Chapter 4 Memory Management Virtual Memory.
CE Operating Systems Lecture 10 Processes and process management in 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.
Operating Systems Process Creation
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Operating Systems CMPSC 473 Processes (3) September Lecture 9 Instructor: Bhuvan Urgaonkar.
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
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
What is a Process ? A program in execution.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Introduction to Kernel
Processes and threads.
Virtualization Virtualize hardware resources through abstraction CPU
Process Management Process Concept Why only the global variables?
Lectures linked lists Chapter 6 of textbook
Processes.
Structure of Processes
Protection of System Resources
Linux Processes & Threads
Structure of Processes
CS 143A Quiz 1 Solution.
System Structure and Process Model
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Process Description and Control
Processes Hank Levy 1.
Processes and Process Management
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lecture 6: Multiprogramming and Context Switching
Chapter 3: Processes.
CSCI 380: Operating Systems William Killian
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Processes Hank Levy 1.
Process Description and Control in Unix
Structure of Processes
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Linux kernel internals Introduction to process descriptors

Upon entering the kernel… A user process will enter ‘kernel-mode’: When it decides to execute a system-call When it is interrupted (e.g. by the timer) When ‘exception’ occurs (e.g. divide by 0)

Switch to kernel-mode stack Entering kernel involves a stack-switch Necessary for robustness: e.g., user-mode stack might be exhausted Desirable for security: e.g, illegal parameters might be supplied

Location of user-mode stack Each task has a private user-mode stack The user-mode stack grows downward from the highest address in user space (i.e., 0xBFFFFFFF) A program’s exit-address is on user stack Command-line arguments on user stack Environment variables on user stack Upon entering ‘main()’:

What’s on the user stack? Upon entering ‘main()’: A program’s exit-address is on user stack Command-line arguments on user stack Environment variables are on user stack During execution of ‘main()’: Function parameters and return-addresses Storage locations for ‘automatic’ variables

What’s on the kernel stack? Upon entering kernel-mode: task’s registers are saved on kernel stack (e.g., address of task’s user-mode stack) During execution of kernel functions: Function parameters and return-addresses Storage locations for ‘automatic’ variables

And also something else! Linux uses part of a task’s kernel-stack to store that task’s ‘process descriptor’ The stack and descriptor are overlayed: union task_union { unsigned longstack[ 2048 ]; struct task_structtask; };

Union of descriptor and stack Room here for stack to expand as needed 8K Process descriptor Kernel-mode stack

The kernel is ‘task manager’ So each task has a ‘process descriptor’: struct task_struct { volatile longstate; unsigned longflags; intsigpending; mm_segment_taddr_limit; /* plus many other fields */ };

The ‘task_union’ object Linux stores stack with process descriptor It allocates 8KB to these combined objects Task’s process descriptor is 1696 bytes So kernel stack can grow to about 6.5KB 8192 bytes – 1696 bytes = 6496 bytes Each ‘task_union’ object is ‘8KB-aligned’

Finding the descriptor info During task-execution in kernel-mode: It’s quick for a process to find its descriptor by using two assembly-language instructions: movl%esp, %ebx andl$0xFFFFE000, %ebx (Now %ebx = descriptor’s base-address)

The ‘current’ process Kernel-headers define useful macros static inline struct task_struct * get_current( void ) { struct task_struct*current; __asm__( “ andl %esp, %0 ; “ \ : “=r” (current) : “0” (~0x1FFF) ); returncurrent; } #define current get_current()

Parenthood New tasks get created by calling ‘fork()’ Old tasks get terminated by calling ‘exit()’ When ‘fork()’ is called, two tasks return One task is known as the ‘parent’ process And the other is called the ‘child’ process The kernel keeps track of this relationship

A parent can have many children If a user task calls ‘fork()’ twice, that will create two distinct ‘child’ processes These children are called ‘siblings’ Kernel keeps track of all this with pointers struct task_struct *p_ptr,// parent *p_cptr,// youngest child *p_ysptr,// younger sibling *p_osptr,// older sibling

Parenthood relationbships P1 P2P3P4 P5 See “Linux Kernel Programming” (Chapter 3) for additional details

The kernel’s ‘process-list’ Kernel keeps a list of process descriptors A ‘doubly-linked’ circular list is used The ‘init_task’ serves as a fixed header Other tasks inserted/deleted dynamically Tasks have forward & backward pointers: struct task_struct *next_task; struct task_struct *prev_task;

Doubly-linked circular list init_task (pid=0) newest task … next_task prev_task

Tasks have ’states’ From kernel-header: #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE1 #define TASK_UNINTERRUPTIBLE2 #define TASK_ZOMBIE4 #define TASK_STOPPED8