170 likes | 364 Views
Process Management in Linux. Brian Doki and Angelo Brigante CSE 258 Linux Project 12/4/99. bdoki@engr.uconn.edu brigante@engr.uconn.edu. High Level Process Description. A process is a dynamic entity. Changes as processor executes instructions.
E N D
Process Management in Linux Brian Doki and Angelo Brigante CSE 258 Linux Project 12/4/99 bdoki@engr.uconn.edu brigante@engr.uconn.edu
High Level Process Description • A process is a dynamic entity. • Changes as processor executes instructions. • Can be thought of as a snapshot of a running program. • Contains the program counter (PC), CPU registers, and stacks for temporary data and addresses. • Current executing process contains all of the current activity in the microprocessor. • A program is passive: just a set of instructions and data.
High Level Process Description • Linux is a multiprocessing OS. • Many processes compete for resources, e.g., the CPU. • Scheduler chooses which processes run and which wait. • Each individual process runs in its own virtual address space. • Processes are incapable of interacting with other processes, except through the kernel. • When one process crashes, it does not cause the other processes to crash.
Lower Level Process Description • In Linux, Processes are also called Tasks. • Each task is represented by a data structure called task_struct. struct task_struct { /* these are hardcoded - don't touch */ volatile long state; unsigned long flags; int sigpending; mm_segment_t addr_limit; struct exec_domain *exec_domain; long need_resched; /* various fields */ long counter; long priority; cycles_t avg_slice; /* SMP and runqueue state */ int has_cpu; int processor; int last_processor; int lock_depth; struct task_struct *next_task, *prev_task; struct task_struct *next_run, *prev_run;/* task state */ struct linux_binfmt *binfmt; int exit_code, exit_signal; int pdeath_signal; unsigned long personality; int dumpable:1; int did_exec:1; pid_t pid; pid_t pgrp; pid_t tty_old_pgrp; pid_t session; /* boolean value for session group leader */ int leader; struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr; /* PID hash table linkage. */ struct task_struct *pidhash_next; struct task_struct **pidhash_pprev; …etc...
The Task Vector • The task_vector is an array of pointers to every task_struct in the system. • The number of system processes is limited to the size of the the task_vector. • Default = 512. • As new processes are created, a new task_struct is allocated from system memory and added to the vector.
The Task Structure • The fields of the task_struct consist of several functional areas. • State • Linux processes can have the following states: • Running: the process is either running or ready to run. • Waiting: the process is waiting for an event or a resource. • Interruptible: can be interrupted. • Uninterruptible: waiting for hardware conditions, so cannot be interrupted. • Stopped: the process has been stopped, e.g., in a debugger.
The Task Structure, cont’d • State, cont’d • Zombie: the process is dead, but still exists as a task_struct in the task_vector for some reason. • Swapping: the process is being swapped. • Scheduling Information • The scheduler needs information to decide which processes gets to run. • Policy: either round-robin or first in, first out. • Priority: the size of the time slice allotted for this process to run. • Rt_priority: used to give real-time processes higher priorities. • Counter: the amount of time a process can run for.
The Task Structure, cont’d • Identifiers • Process identifier • Not the index to the task_vector, just a number. • User and group identifiers • Used to control access to files and devices in the system. • Interprocess Communication • Contains info on signals, pipes, semaphores, shared memory, and message queues used by the process.
The Task Structure, cont’d • Links • Except for the initial process, every task has a parent process. • When new processes are created, they are cloned from previous processes. • Each task_struct contains pointers to its parent and its siblings as well as to its child processes. • Use the Linux command pstree to display the “family relationship” between running processes. • All tasks in the system are also held in a doubly linked list whose root is the task_struct of the init process. This allows Linux to look at every process in the system (necessary for commands such as ps and kill.)
The Task Structure, cont’d • Times and Timers • At each clock tick, the kernel keeps track of the amount of time a task has spent in system and user mode. • Linux time interval units are called jiffies. • Processes also can contain interval timers that use system calls to send signals when the timers expire. • File System • Processes can open and close files • Each task_struct contains pointers to each open file, as well as pointers to to VFS inodes, which provide interfaces to the underlying file system.
The Task Structure, cont’d • Virtual Memory • The mapping of a task’s virtual memory onto the system’s physical memory is described here. • Processor Specific Content • Again, a process is like a snapshot of the system’s current state. • When a process is suspended, the entire state of the CPU (the CPU context) must be saved in the task_struct. • Registers, stacks, etc. • When the scheduler restarts a process, the CPU context is restored from here.
Priority • The Scheduler decides which process on the run queue deserves to run. • Real time processes receive the highest weighting, and will always run before normal processes. • Normal weighting is the counter value; real time processes have a weight of counter + 1000. • The current process is always at a disadvantage because its counter has already been decremented. • If more than one process has the same priority, the one nearest to the front of the queue is chosen.
Concluding Remarks/Looking Ahead • Review of Processes, what they are and how Linux sees them. • Processes are tasks, stored in a data structure called task_struct. • All tasks on a system are stored in a vector called task_vector. • The scheduler generates a run queue from the task vector and executes the tasks based on the scheduling policy and the tasks’ priorities. • Related topics … • Process Scheduler in Linux • Pre-emptive Scheduling in Linux