Download presentation
Presentation is loading. Please wait.
1
Processes David Ferry, Chris Gill
CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63143
2
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
3
What is a Process, Really?
A 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
4
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
5
CSE 422S –Operating Systems Organization
Process States Alive states: TASK_RUNNING: running or runnable TASK_INTERRUPTIBLE: blocked on wait queue TASK_UNINTERRUPTIBLE: short duration blocking, can’t receive signals __TASK_TRACED: being traced with syscall ptrace __TASK_STOPPED: cannot execute (SIGSTOP, debugger) Exit states: EXIT_ZOMBIE: exited but has not been waited for (kernel structures still exit) EXIT_DEAD: exited and has been waited for CSE 422S –Operating Systems Organization
6
Handling Processes in Linux
Linux uses many containers to ensure efficient access to processes: Linked list of all processes Lists of child processes PID hash table Processor run queues Blocking I/O wait queues Helper functions: for_each_process() list_for_each(list, task->children) task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 task_struct ptr* 0x1 ptr* 0x2 ptr* 0x3 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. C has limited classes / polymorphism Logic and code for handling all runnable objects is the same 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.