免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 852 | 回复: 0
打印 上一主题 下一主题

Processes(九) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-20 16:05 |只看该作者 |倒序浏览

                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 the choices shown in the following list.
运行队列list管理所有TASK_RUNNING状态的进程。当管理其他状态的进程时,不同状态需要不同类型的处理,Linux在下列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 the
child processes for a particular parent.
          处在TASK_STOPED、EXIT_ZOMBIE或者EXIT_DEAD状态的进程并不链接到特殊的list。没有必要管理处在这三种状态之一的进程,因为已停止、僵死和已死的进程只有通过PID或某个进程的子进程list访问。
·         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.
          处在task_interruptible或者TASK_UNINTERRUPTIBLE状态的进程分成很多类,每类对应一个特定的事件。在这种情形下,进程状态没有提供足够的信息来快速地获得进程,因此引入额外的进程list是有必要的。这些list也称作等待队列。
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'll just say here that a process must often wait for some event 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, which are woken up by the
kernel when some condition becomes true.
等待队列在内核中有几个用途,尤其是用于中断处理,进程同步和定时。这些内容以后会讨论,在这里我们只是说进程必须经常等待某些事件的发生,比如磁盘操作的结束,系统资源的释放,或者固定时间的流逝。等待队列实现了在事件上有条件的等待:一个希望等待某个特定的事件的进程将它自己放在合适的等待队列并放弃运行。因此,一个等待队列表示了睡眠进程的集合,当某个条件变为真时,内核将这些进程唤醒。
Wait queues are implemented as doubly linked lists 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:
等待队列实现为一个双向链表,它的元素包括了进程描述符的指针。每个等待队列由一个等待队列头,一种类型为wait_queue_head_t的结构标识:
    struct _ _wait_queue_head {
        spinlock_t lock;
        struct list_head task_list;
    };
    typedef struct __wait_queue_head 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 induce unpredictable results (see Chapter 5). 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.
因为等待队列是由中断处理函数和一个主要的内核函数修改,这个双向链表必须被保护以避免并发访问的发生,否则会产生不可预知的结果。同步通过等待队列头中的自旋锁lock实现。成员task_list是等待进程链表的头。
Elements of a wait queue list are of type wait_queue_t:
    struct _ _wait_queue {
        unsigned int flags;
        struct task_struct * task;
        wait_queue_func_t func;
        struct list_head task_list;
    };
    typedef struct _ _wait_queue 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.
等待队列中的每个元素表示一个正睡觉的进程,它正在等待某个事件的发生;它的描述符地址存放在task成员中。成员task_list包含了将这个元素链接到等待同一事件的进程链表的指针。
However, it is not always convenient 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, while the other processes continue to sleep. (This avoids a problem known as the "thundering herd," with which multiple processes are wakened only to race for a resource that can be accessed by one of them, with the result that remaining processes must once more be put back to sleep.)
然而,将一个等待队列中的所有睡眠进程都唤醒并不总是方便的。比如,当两个或更多的进程等待互斥地访问某个资源的释放,仅将等待队列中的一个进程唤醒就很好理解了。这个进程占用了这个资源,而其他进程继续睡眠。(这避免了所谓“惊群”的问题,多个进程被唤醒去竞争一个只能由其中之一可以访问的资源,结果剩下的进程必须再度回去睡觉,这不瞎折腾吗)。
Thus, there are two kinds of sleeping processes: exclusive processes (denoted by the value 1 in the flags field of the corresponding wait queue element) are selectively woken up by the kernel, while nonexclusive processes (denoted by the value 0 in the flags field) are always woken up by the kernel when the event occurs. A process waiting for a resource that can be granted to just one process at a time is a typical exclusive process. Processes waiting for an event that may concern any of them are nonexclusive. Consider, for instance, a group
of processes that are waiting for the termination of a group of disk block transfers: as soon as the transfers complete, all waiting processes must be woken up. As we'll see next, the func field of a wait queue element is used to specify how the processes sleeping in the wait queue should be woken up.
因此将睡眠进程划分成两种:独占进程(对应等待队列元素的flags成员置1表示)由内核有选择地唤醒,而非独占进程(flags置0)在事件发生时,内核总是会唤醒它。等待某种同一时刻只能由一个进程访问的资源的进程是典型的独占进程。等待影响所有进程事件的进程是非独占的。比如,考虑一组进程正在等待一组磁盘块传输的结束:一旦传输结束,所有等待的进程都必须被唤醒。等待队列元素中的func成员用来指明等待队列中的睡眠进程应该如何被唤醒。
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/65228/showart_570219.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP