1 / 13

Process Management in Linux

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.

hawa
Download Presentation

Process Management in Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Process Management in Linux Brian Doki and Angelo Brigante CSE 258 Linux Project 12/4/99 bdoki@engr.uconn.edu brigante@engr.uconn.edu

  2. 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.

  3. 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.

  4. 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...

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.)

  10. 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.

  11. 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.

  12. 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.

  13. 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

More Related