ULK --- Chap3 Processes: How Processes Are Organized

The runqueue lists group all processes in a  TASK_RUNNING state. When it comes to grouping

processes in other states, the various states call for different types of treatment, with Linux

opting for one of choices shown in the following list.

Processes in a TASK_STOPPED, EXIT_ZOMBIE, or EXIT_DEAD state are not linked in specific lists.

There is no need to group processes in any of these three states, because stopped, zombie, and

dead processes are accessed only via PID or via linked lists of child process for a particular parent.

Processes in a TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE state are subdivided into many

classes, each of which corresponds to a specific event. In this case, the process state does not

provide enough information to retrieve the process quickly, so it is necessary to introduce additional

lists of processes. These are called wait queues and are discussed next.

                        Wait Queues

Wait queues have several uses in the kernel, particularly for interrupt handling, process synchronization,

and timing. Because these topics are discussed in later chapters, we will just say here that a process

must often wait for some events to occur, such as for a disk operation to terminate, a system resource

to be released, or a fixed interval of time to elapse. Wait queues implement conditional waits on events:

a process wishing to wait for a specific event places itself in the proper wait queue and relinquishes control.

Therefore, a wait queue represents a set of sleeping processes, whch are woken up by the kernel when

some condition becomes true.

Wait queues are implemented as doubly linked list whose elements include pointers to process descriptors.

Each wait queue is identified by a wait queue head, a data structure of type wait_queue_head_t:

Because wait queues are modified by interrupt handlers as well as by major kernel functions, the doubly

linked lists must be protected from concurrent accesses, which could include unpredictable results.

Synchronization is achieved by the lock spin lock in the wait queue head. The task_list field is the head of

the list of waiting processes.

Elements of a wait queue list are of type wait_queue_t:

Each element in the wait queue list represents a sleeping process, which is waiting for some event to occur;

its descriptor address is stored in the task field. The task_list field contains the pointers that link this element

to the list of processes waiting for the same event.

However, it is not always convention to wake up all sleeping processes in a wait queue. For instance, if two

or more processes are waiting for exclusive access to some resource to be released, it makes sense to wake

up just one process in the wait queue. This process takes the resource, which the other processes continue to

sleep.

时间: 2024-08-26 14:44:32

ULK --- Chap3 Processes: How Processes Are Organized的相关文章

ULK --- Chap3 Processes

The concept of a process is fundamental to any multiprogramming operating system. A process is usually defined as an instance of a program in execution; thus, if 16 users are running vi at once, there are 16 separate processes (although they can shar

ULK --- Chap3 Processes: Doubly linked lists

Before moving to and describing how the kernel keeps track of the various processes in the system, we would like to emphasize the role of special data structures that implement doubly linked lists. For each list, a set of primitives operations must b

ULK --- Chap3 Processes: Lists of Tasking_Running processes

When looking for a new process to run on a CPU, the kernel has to consider only the runnable processes (that is, the processes in the TASK_RUNNING state). Earlier Linux version put all runnable processes in the same list called runqueue. Because it w

ULK --- Chap3 Processes: Relationships Among Processes

Processes created by a  program have a parent/child relationship. When a process creates multiple children, these children have sibling relationships. Several fields must be introduced in a process descriptor to represent these relationships; Process

ULK --- Chap3 Processes: Identifying a Process

As a general rule, each execution context that can be independently scheduled must have its own process descriptor; therefore, even lightweight processes, which share a large portion of their kernel data structures, have their own task_struct structu

ULK --- Chap3 Processes: Process Descriptor Handling

Processes are dynamic entities whose lifetimes range from a few milliseconds to months. Thus, the kernel must be able to handle many processes at the same time, and process descriptors are stored in dynamic memory rather than in the memory area perma

Show All Running Processes in Linux

ps由于历史的原因,所以很奇特,有些命令必须加"-",比如: ps A 上面的写法是错误的 ********* simple selection ********* ********* selection by list ********* -A all processes -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session le

Introduction to Gaussian Processes

Introduction to Gaussian Processes Gaussian processes (GP) are a cornerstone of modern machine learning. They are often used for non-parametric regression and classification, and are extended from the theory behind Gaussian distributions and Gaussian

Processes vs Threads

A process is an executing instance of an application. What does that mean? Well, for example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can con