Download presentation
Presentation is loading. Please wait.
Published byAugusta Johns Modified over 5 years ago
1
Processes David Ferry, Chris Gill, Brian Kocoloski
CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63143
2
Resource Virtualization
What resources do you use when you write programs? The processor(s) Memory Files Data (global variables, things like hardcoded strings) What do you not have to worry about generally? Existence of other processes State of hardware resources CSE 422S – Operating Systems Organization
3
Resource Virtualization
The operating system virtualizes physical hardware resources into virtual resources in the form of processes Physical Memory Physical Processors CSE 422S – Operating Systems Organization
4
Resource Virtualization
Process 1 Process 2 Processor Virtualization: Two (or more) processes may share the same set of physical CPUs How to share them? CPU scheduling (next week) Memory Virtualization: Translate private memory addresses to physical addresses Virtual memory (in a few weeks) Physical Memory Physical Processors CSE 422S – Operating Systems Organization
5
CSE 422S – Operating Systems Organization
Processes in Linux Fundamental process abstraction: Original: Each process behaves as though it has total control over the system Modern: Threads still execute as though they monopolize the system, but the process abstraction also facilitates multi-threading, signals, and inter-process communication More features: Multi-threading Scheduling Shared memory Virtual Memory Sockets Process accounting etc. Signals Process groups Synchronization CSE 422S – Operating Systems Organization
6
CSE 422S – Operating Systems Organization
Tasks in Linux A task/process is an execution stack together with data that describes the process state. (also describes threads) Two stacks: Kernel mode User mode Data: thread_info: small, efficient task_struct: large, statically allocated by slab allocator, points to other data structs User side: Kernel side: User Stack thread_info Kernel stack task_struct .bss .data .text CSE 422S – Operating Systems Organization
7
CSE 422S – Operating Systems Organization
One Size Fits All Processes, threads, and kernel threads are all implemented with the same data structures (thread_info and task_struct) and functions. Threads are like user processes but they share their parent’s address space. Kernel threads don’t have a user-side address space (i.e. mm_struct pointer is NULL) and not all data values are used. CSE 422S – Operating Systems Organization
8
Threads, Processes, and Kernel Threads
Address space thread_info Kernel level Kernel stack .bss (static variables) User level .text (executable code) .data (heap) User stack CSE 422S – Operating Systems Organization
9
Threads, Processes, and Kernel Threads
<set stack pointer to kernel address> <set page table to kernel memory> Address space thread_info Kernel level Kernel stack .bss (static variables) User level main() syscall() .text (executable code) .data (heap) User stack CSE 422S – Operating Systems Organization
10
Threads, Processes, and Kernel Threads
// current is a user-level process struct task_struct * task = current; struct mm_struct * mm = current->mm; Address space thread_info Kernel level Kernel stack .bss (static variables) User level .text (executable code) .data (heap) User stack CSE 422S – Operating Systems Organization
11
Threads, Processes, and Kernel Threads
// current is a kernel thread // (recall, look for processes named // “k …” in ‘ps –aux’) struct task_struct * task = current; struct mm_struct * mm = current->mm; Address space thread_info Kernel level Kernel stack User level NULL CSE 422S – Operating Systems Organization
12
Threads, Processes, and Kernel Threads
struct task_struct * task1; struct task_struct * task2; // fetch task_structs for 2 threads of the same process task1->mm; task2->mm Task 2 Task 1 .bss (static variables) .text (executable code) .data (heap) User level stack stack Stacks are specific per-thread CSE 422S – Operating Systems Organization
13
Creating a New Process: fork() and clone()
Duplicate existing process Initialize per-PID data PID, real_parent, statistics If new process: Copies file handles, signal handlers, process address space, etc. Resources shared via page-level lazy copy-on-write* If new thread: Shares pointers to above resources thread_info Kernel stack task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 thread_info Kernel stack task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 *E.g. Every process in the system shares the same “copy” of the C library CSE 422S – Operating Systems Organization
14
CSE 422S – Operating Systems Organization
Kernel Source Clearly illustrated in kernel/fork.c:_do_fork() (line 2018) copy_process() (line 2047) get_task_pid() (line 2060) Kernel thread creation kernel_thread() (line 2107) Process creation via copying kernel/fork.c():copy_process() (line 1537) Lines 1740 through 1764 CSE 422S – Operating Systems Organization
15
CSE 422S – Operating Systems Organization
Today’s Studio Explore user-space utilities for process discovery and creation Explore kernel-level data structures used for process management struct task_struct More experience with kernel modules CSE 422S – Operating Systems Organization
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.