The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version 2.6.10.

Slides:



Advertisements
Similar presentations
Linux kernel internals Introduction to process descriptors.
Advertisements

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
The ‘process’ abstraction
The ‘thread’ abstraction A look at the distinction between the idea of a ‘process’ and the concept of a ‘thread’
CS591 (Spring 2001) The Linux Kernel: Process Management.
Processes CSCI 444/544 Operating Systems Fall 2008.
Linux Memory Management High-Level versus Low-Level.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
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.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
4.7.1 Thread Signal Delivery Two types of signals –Synchronous: Occur as a direct result of program execution Should be delivered to currently executing.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes ULK Chapter 3 COMS W4118 Spring Outline Processes/tasks The process descriptor: task_struct Thread context Task States Process relationships.
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.
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Character Device Driver – Characteristics and functionality – Basic IO functions Multi tasking (pre requisite.
Introduction to Processes CS Intoduction to Operating Systems.
Implementing Processes and Process Management Brian Bershad.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Chapter 3 Process Description and Control
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,
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
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.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Threads G.Anuradha (Reference : William Stallings)
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.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
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.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
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
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
What is a Process ? A program in execution.
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
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Chapter 4 – Thread Concepts
Introduction to Kernel
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Protection of System Resources
Chapter 4 – Thread Concepts
Processes David Ferry, Chris Gill
Linux kernel: Processes, threads and scheduling
More examples How many processes does this piece of code create?
Process Description and Control
Processes Hank Levy 1.
Processes and Process Management
Process Description and Control
Lecture 6: Multiprogramming and Context Switching
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Processes Hank Levy 1.
Implementing Processes, Threads, and Resources
Processes David Ferry, Chris Gill, Brian Kocoloski
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version 2.6.10

Multi-tasking Modern operating systems allow multiple users to share a computer’s resources Users are allowed to run multiple tasks The OS kernel must protect each task from interference by other tasks, while allowing every task to take its turn using some of the processor’s available time

Stacks and task-descriptors To manage multitasking, the OS needs to use a data-structure which can keep track of every task’s progress and usage of the computer’s available resourcres (physical memory, open files, pending signals, etc.) Such a data-structure is called a ‘process descriptor’ – every active task needs one Every task needs its own ‘private’ stack

What’s on a program’s 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

Entering the kernel… A user process enters ‘kernel-mode’: when it decides to execute a system-call when it is ‘interrupted’ (e.g. by the timer) when ‘exceptions’ occur (e.g. divide by 0)

Switching to a different stack Entering kernel-mode involves not only a ‘privilege-level transition’ (from level 3 to level 0), but also a stack-area ‘switch’ This is necessary for robustness: e.g., user-mode stack might be exhausted This is desirable for security: e.g, privileged data might be accessible

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

Supporting structures So every task, in addition to having its own code and data, will also have a stack-area that is located in user-space, plus another stack-area that is located in kernel-space Each task also has a process-descriptor which is accessible only in kernel-space

A task’s virtual-memory layout Process descriptor and kernel-mode stack Kernel space User space Privilege-level 0 User-mode stack-area Privilege-level 3 Task’s code and data

Something new in 2.6 Linux uses part of a task’s kernel-stack page-frame to store ‘thread information’ The thread-info includes a pointer to the task’s process-descriptor data-structure Task’s kernel-stack struct task_struct Task’s process-descriptor Task’s thread-info kernel page-frame

Tasks have ’states’ From kernel-header: <linux/sched.h> #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 #define TASK_ZOMBIE 4 #define TASK_STOPPED 8

Fields in a process-descriptor struct task_struct { volatile long state; struct thread_into *thread_info; unsigned long flags; struct mm_struct *mm; pid_t pid; char comm[16]; /* plus many other fields */ };

Finding a task’s ‘thread-info’ During a task’s execution in kernel-mode, it’s very quick to find that task’s thread-info object Just use two assembly-language instructions: movl $0xFFFFF000, %eax andl %esp, %eax Ok, now %eax = the thread-info’s base-address There’s a macro that implements this computation

Finding the task-descriptor Use a macro ‘current_thread_info()’ to get a pointer to the ‘thread_info’ structure: struct thread_info *info = current_thread_info(); Then one more step gets you the address of the task’s process-descriptor: struct task_struct *task = info->task; You can also use ‘current’ to perform this two-step assignment: task = 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 track of all this with lists of pointers

Parenthood relationships See “Linux Kernel Programming” (Chapter 3) for additional details

The kernel’s ‘task-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, implemented as fields in the ‘tasks’ field To go forward: task = next_task( task ); To go backward: task = prev_task( task );

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

Demo We can write a module that lets us create a pseudo-file (named ‘/proc/tasklist’) for viewing the list of all currently active tasks Our ‘tasklist.c’ module shows the name and process-ID of each task, along with the task’s current state Use the command: $ cat /proc/tasklist

In-class exercise #1 Different versions of the 2.6 Linux kernel use slightly different definitions for these task-related kernel data-structures (e.g, our 2.6.10 kernel uses a smaller-sized ‘thread-info’ structure than 2.6.9 did) So can you write an installable kernel module that will tell you: the size of a ‘task_struct’ object (in bytes)? the size of a ‘thread_info’ object (in bytes)?

‘Kernel threads’ Some tasks don’t have a page-directory of their own – because they don’t need one They can just ‘borrow’ the page-dirtectory that belongs to another task These ‘kernel thread’ tasks will have an NULL value (i.e., zero) stored in the ‘mm’ field of their ‘task_struct’ descriptor

In-class exercise #2 Can you modify our ‘tasklist.c’ module so it will display a list of only those tasks which are kernel threads?