Processes ULK Chapter 3 COMS W4118 Spring 2008 Outline Processes/tasks The

 www.phwiki.com

 

The Above Picture is Related Image of Another Journal

 

Processes ULK Chapter 3 COMS W4118 Spring 2008 Outline Processes/tasks The

Coppin State College, US has reference to this Academic Journal, Processes ULK Chapter 3 COMS W4118 Spring 2008 Outline Processes/tasks The process descriptor: task_struct Thread context Task States Process relationships Wait queues Kernel threads Context switching Creating processes Destroying processes The major header files used in consideration of process management are: include/linux/sched.h ? declarations in consideration of most task data structures include/linux/threads.h ? some configuration constants (unrelated so that threads) include/linux/times.h ? time structures include/linux/time.h ? time declarations include/linux/timex.h ? wall clock time declarations Header Files

 Toscano, Marlene Coppin State College www.phwiki.com

 

Related University That Contributed for this Journal are Acknowledged in the above Image

 

Source Code The source code in consideration of process in addition to thread management is in the kernel directory: sched.c ? task scheduling routines signal.c ? signal handling routines fork.c ? process/thread creation routines exit.c ? process exit routines time.c ? time management routines timer.c ? timer management routines The source code in consideration of the program initiation routines is in fs/exec.c. Linux: Processes or Threads? Linux uses a neutral term: tasks Tasks represent both processes in addition to threads Linux view Threads: processes that share address space Linux “threads” (tasks) are really “kernel threads? Lighter-weight than traditional processes File descriptors, VM mappings need not be copied Implication: file table in addition to VM table not part of process descriptor Stacks in addition to task-descriptors To manage multitasking, the OS needs so that use a data-structure which can keep track of every task?s progress in addition to usage of the computer?s available resources (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 So every task, in addition so that having its own code in addition to 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 User space Kernel space User-mode stack-area Task?s code in addition to data Privilege-level 0 Privilege-level 3 process descriptor in addition to kernel-mode stack Shared runtime-libraries Process Descriptor Process ? dynamic, program in motion Kernel data structures so that maintain “state” Descriptor, PCB (control block), task_struct Larger than you think! (about 1K) Complex struct alongside pointers so that others Type of info in task_struct state, id, priorities, locks, files, signals, memory maps, locks, queues, list pointers, ? Some details Address of first few fields hardcoded in asm Careful attention so that cache line layout The Linux process descriptor task_struct state *stack flags *mm exit_code *user pid *files *parent mm_struct *pgd pagedir[] user_struct signal_struct *signal files_struct Each process descriptor contains many fields in addition to some are pointers so that other kernel structures which may themselves include fields that point so that structures

Hume?s Central Principles 4(a) From the Idea of Causation so that Induction The Idea of Causation Contiguity in addition to Priority Necessary Connexion To Neighbouring Fields The Causal Maxim Leading Up so that Induction ?Of the impressions of the senses in addition to memory? Recap ? the road so that Treatise 1.3.6 4(b) The Argument concerning Induction The Famous Argument (?3) Streamlining the Argument Causal Inference Is Not A Priori (1) A Thought Experiment Causal Inference Is Not A Priori (2) Experience in addition to Constant Conjunction ?Perhaps ?twill appear in the end ?? A Question of Faculties The Need in consideration of Extrapolation UP: The Uniformity Principle UP in the Enquiry The Role of the Uniformity Principle Can UP be Founded on Argument? Enquiry More Complete The ?Sceptical? Conclusion Argument Summary (in 2 Slides) Hume?s Argument concerning Induction Four ?Kinds of Evidence? (Again) Debating Hume?s Argument What Does ?Reason? Mean? Inductive Inferences as ?Reason? Reducing the Field Agreeing alongside Garrett ? ? Up so that a Point ?Reason? in addition to ?Reasoning? ?Deduction? in addition to ?Ratiocination? Hume?s Usage Hume?s Conclusion (Garrett 1997) What About Intuition? Reason = The Understanding A Sign of Convergence? ? Epistemology or Cognitive Science? Hume?s Conclusion (Garrett 2002) Induction in General, or Individual? The Inheritance Problem An Implausible Non-Sequitur Further Logical Objections Arguments Can Be Bad! Induction from the Causal Maxim Price on the Causal Maxim in addition to Induction ?Reason is ?? ?Reason? as Our Cognitive Faculty Induction as Part of Reason ? ? But Not ?Founded on Reason? A Crucial Step ? ? Which is ?Imagination-Like? Reason in addition to the Imagination

The Task Structure The task_struct is used so that represent a task. The task_struct has several sub-structures that it references: tty_struct ? TTY associated alongside the process fs_struct ? current in addition to root directories associated alongside the process files_struct ? file descriptors in consideration of the process mm_struct ? memory areas in consideration of the process signal_struct ? signal structures associated alongside the process user_struct ? per-user information (for example, number of current processes) Thread Context Linux uses part of a task?s kernel-stack page-frame so that store thread information The thread_info includes a pointer so that the task?s process-descriptor data-structure Task?s kernel-stack Task?s thread-info page-frame aligned Task?s process-descriptor struct task_struct 8-KB Finding a task?s ?thread-info? During a task?s execution in kernel-mode, it?s very quick so that find that task?s thread_info object Just use two assembly-language instructions: movl $0xFFFFE000, %eax andl %esp, %eax Ok, now %eax = the thread-info?s base-address Masking off 13 bits of the stack yields thread_info Macro current_thread_info implements this computation thread_info points so that task_struct current macro yields the task_struct current is not a static variable, useful in consideration of SMP

Finding task-related kernel-data Use a macro ?task_thread_info( task )? so that get a pointer so that the ?thread_info? structure: struct thread_info *info = task_thread_info( task ); Then one more step gets you back so that the address of the task?s process-descriptor: struct task_struct *task = info->task; PID Hashes in addition to Task Lookup PID: 16-bit process ID task_structs are found by searching in consideration of pid structures, which point so that the task_structs. The pid structures are kept in several hash tables, hashed by different IDs: process ID thread group ID // pid of first thread in process process group ID // job control session ID // login sessions (see include/linux/pid.h) Allocated process IDs are recorded in a bitmap representing around four million possible IDs. PIDs dynamically allocated, avoid immediate reuse Process Relationships Processes are related Parent/child (fork()), siblings Possible so that “re-parent” Parent vs. original parent Parent can “wait” in consideration of child so that terminate Process groups Possible so that send signals so that all members Sessions Processes related so that login

Task Relationships Several pointers exist between task_structs: parent ? pointer so that parent process children ? pointer so that linked list of child processes sibling ? pointer so that task of “next younger sibling” of current process children in addition to sibling point so that the task_struct in consideration of the first thread created in a process. The task_struct in consideration of every thread in a process has the same pointer values. Task States From kernel-header: #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 #define TASK_STOPPED 4 #define TASK_TRACED 8 #define EXIT_ZOMBIE 16 #define EXIT_DEAD 32 #define TASK_NONINTERACTIVE 64 #define TASK_DEAD 128 Task States TASK_RUNNING ? the thread is running on the CPU or is waiting so that run TASK_INTERRUPTIBLE ? the thread is sleeping in addition to can be awoken by a signal (EINTR) TASK_UNINTERRUPTIBLE ? the thread is sleeping in addition to cannot be awakened by a signal TASK_STOPPED ? the process has been stopped by a signal or by a debugger TASK_TRACED ? the process is being traced via the ptrace system call TASK_NONINTERACTIVE ? the process has exited TASK_DEAD ? the process is being cleaned up in addition to the task is being deleted

Exit States 135 * We have two separate sets of flags: task->state 136 * is about runnability, while task->exit_state are 137 * about the task exiting. Confusing, but this way 138 * modifying one set can’t modify the other one by 139 * mistake. EXIT_ZOMBIE ? the process is exiting but has not yet been waited in consideration of by its parent EXIT_DEAD ? the process has exited in addition to has been waited in consideration of List Operations The list_head is a generic list structure alongside a set of services: LIST_HEAD ? declare in addition to initialize list head list_add ? add a list_head after item list_add_tail ? add a list_head before item list_del ? remove list_head from list list_del_init ? remove in addition to initialize list_head list_empty ? is a list empty? list_for_each, list_for_each_entry, list_entry 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 init_task (pid=0) newest task ? next prev ?run? queues in addition to ?wait? queues In order in consideration of Linux so that efficiently manage the scheduling of its various ?tasks?, separate queues are maintained in consideration of ?running? tasks in addition to in consideration of tasks that temporarily are ?blocked? while waiting in consideration of a particular event so that occur (such as the arrival of new data from the keyboard, or the exhaustion of prior data sent so that the printer) Some tasks are ?ready-to-run? Those tasks that are ready-to-run comprise a sub-list of all the tasks, in addition to they are arranged on a queue known as the ?run-queue? Those tasks that are blocked while awaiting a specific event so that occur are put on alternative sub-lists, called ?wait queues?, associated alongside the particular event(s) that will allow a blocked task so that be unblocked run_queue init_task list

Kernel Wait Queues waitqueue waitqueue waitqueue waitqueue wait_queue_head_t can have 0 or more wait_queue_t chained onto them However, usually just one element Each wait_queue_t contains a list_head of tasks All processes waiting in consideration of specific “event? Used in consideration of timing, synch, device i/o, etc. wait_queue_head_t wait_queue_t How Do I Block? By calling one of the sleep_on functions: sleep_on, interruptible_sleep_on, sleep_on_timeout, etc. These functions create a wait_queue in addition to place the calling task on it Modify the value of its ?state? variable: TASK_UNINTERRUPTIBLE TASK_INTERRUPTIBLE Then call schedule or schedule_timeout The next task so that run calls deactivate_task so that move us out of the run queue Only tasks alongside ?state == TASK_RUNNING? are granted time on the CPU by the scheduler How Do I Wake Up? By someone calling one of the wake functions: wake_up, wake_up_all, wake_up_interruptible, etc. These functions call the curr->func function so that wake up the task Defaults so that default_wake_function which is try_to_wake_up try_to_wake_up calls activate_task so that move us out of the run queue The ?state? variable is set so that TASK_RUNNING Sooner or later the scheduler will run us again We then return from schedule or schedule_timeout

What are all these options? INTERUPTIBLE vs. NON-INTERUPTIBLE: Can the task be woken up by a signal? TIMEOUT vs no timeout: Wake up the task after some timeout interval EXCLUSIVE vs. NON-EXCLUSIVE: Should only one task be woken up? Only one EXCLUSIVE task is woken up Kept at end of the list All NON-EXCLUSIVE tasks are woken up Kept at head of the list Functions alongside _nr option wake up number of tasks Other Wait Queue Notes Process can wakeup alongside event not true If multiple waiters, another may have resource Always check availability after wakeup Maybe wakeup was in response so that signal ?Interruptible? functions are preferred sleep_on functions are deprecated sleep_on functions suffer from race conditions Want so that atomically test in addition to sleep prepare_to_wait functions preferred wait_queue usually allocated on kernel stack Why is that OK? Context Switch Context switching is the process of saving the state of the currently running task in addition to loading the state of the next task so that run. This involves saving the task’s CPU state (registers), changing the current task value, in addition to loading the CPU state of the new task into the registers. schedule determines the next task so that run, calls context_switch, which calls switch_mm so that change the process address space, then calls switch_to so that context switch so that the new task.

Descriptor Storage/Allocation Descriptors stored in kernel data segment Each process gets a 2 page (8K) “kernel stack” used while in the kernel (security) task_struct stored here; rest in consideration of stack Easy so that derive descriptor from esp (stack ptr) Implemented as union task_union { } Small (16) cache of free task_unions free_task_struct(), alloc_task_struct() Task Serialization Allocation of substructures of the task_struct is serialized alongside the alloc_lock in the task_struct. This lock is also used when first accessing any of the substructures of the task_struct. Manipulation of the lists that a task_struct is on is serialized by disabling local interrupts in addition to holding the global read/write lock tasklist_lock.

Toscano, Marlene Member of Editorial Board

Toscano, Marlene is from United States and they belong to Member of Editorial Board and work for Geoforum in the AZ state United States got related to this Particular Article.

Journal Ratings by Coppin State College

This Particular Journal got reviewed and rated by Kernel Wait Queues waitqueue waitqueue waitqueue waitqueue wait_queue_head_t can have 0 or more wait_queue_t chained onto them However, usually just one element Each wait_queue_t contains a list_head of tasks All processes waiting in consideration of specific “event? Used in consideration of timing, synch, device i/o, etc. wait_queue_head_t wait_queue_t How Do I Block? By calling one of the sleep_on functions: sleep_on, interruptible_sleep_on, sleep_on_timeout, etc. These functions create a wait_queue in addition to place the calling task on it Modify the value of its ?state? variable: TASK_UNINTERRUPTIBLE TASK_INTERRUPTIBLE Then call schedule or schedule_timeout The next task so that run calls deactivate_task so that move us out of the run queue Only tasks alongside ?state == TASK_RUNNING? are granted time on the CPU by the scheduler How Do I Wake Up? By someone calling one of the wake functions: wake_up, wake_up_all, wake_up_interruptible, etc. These functions call the curr->func function so that wake up the task Defaults so that default_wake_function which is try_to_wake_up try_to_wake_up calls activate_task so that move us out of the run queue The ?state? variable is set so that TASK_RUNNING Sooner or later the scheduler will run us again We then return from schedule or schedule_timeout and short form of this particular Institution is US and gave this Journal an Excellent Rating.