Linux进程管理

学习过程中将查询的东西记录。

从找thread_info的定义出发,开始打算根据最新版本4.15.9(linux-4.15.9/arch/x86/include/asm/thread_info.h),后来发现thread_info的定义变了,所以以下还是从Linux-2.6.22.6中找到的定义。

 

linux-2.6.22.6/include/asm-x86_64/thread_infoh.h

struct thread_info {

       struct task_struct  *task;             /* main task structure */

       struct exec_domain      *exec_domain;      /* execution domain */

       __u32                   flags;             /* low level flags */

       __u32                   status;           /* thread synchronous flags */

       __u32                   cpu;        /* current CPU */

       int                preempt_count;    /* 0 => preemptable, <0 => BUG */

 

       mm_segment_t           addr_limit;    

       struct restart_block    restart_block;

 

};

preemptable可抢占的

 

linux-2.6.22.6/include/linux/list.h

/*

 * Simple doubly linked list implementation.

 *

 * Some of the internal functions ("__xxx") are useful when

 * manipulating whole lists rather than single entries, as

 * sometimes we already know the next/prev entries and we can

 * generate better code by using them directly rather than

 * using the generic single-entry routines.

 */

 

struct list_head {

       struct list_head *next, *prev;

};

 

/**

 * list_entry - get the struct for this entry

 * @ptr: the &struct list_head pointer.

 * @type:      the type of the struct this is embedded in.

 * @member: the name of the list_struct within the struct.

 */

#define list_entry(ptr, type, member) \

       container_of(ptr, type, member)

 

/**

 * list_first_entry - get the first element from a list

 * @ptr: the list head to take the element from.

 * @type:      the type of the struct this is embedded in.

 * @member: the name of the list_struct within the struct.

 *

 * Note, that list is expected to be not empty.

 */

#define list_first_entry(ptr, type, member) \

       list_entry((ptr)->next, type, member)

目测list中第一个是空的

 

/**

 * list_for_each     -     iterate over a list

 * @pos: the &struct list_head to use as a loop cursor.

 * @head:     the head for your list.

 */

#define list_for_each(pos, head) \

       for (pos = (head)->next; prefetch(pos->next), pos != (head); \

               pos = pos->next)

 

/**

 * __list_for_each  -     iterate over a list

 * @pos: the &struct list_head to use as a loop cursor.

 * @head:     the head for your list.

 *

 * This variant differs from list_for_each() in that it's the

 * simplest possible list iteration code, no prefetching is done.

 * Use this for code that knows the list to be very short (empty

 * or 1 entry) most of the time.

 */

#define __list_for_each(pos, head) \

       for (pos = (head)->next; pos != (head); pos = pos->next)

 

/**

 * list_for_each_entry   -     iterate over list of given type

 * @pos: the type * to use as a loop cursor.

 * @head:     the head for your list.

 * @member: the name of the list_struct within the struct.

 */

#define list_for_each_entry(pos, head, member)                           \

       for (pos = list_entry((head)->next, typeof(*pos), member);    \

            prefetch(pos->member.next), &pos->member != (head); \

            pos = list_entry(pos->member.next, typeof(*pos), member))

 

linux-2.6.22.6/include/linux/kernel.h

/**

 * container_of - cast a member of a structure out to the containing structure

 * @ptr: the pointer to the member.

 * @type:      the type of the container struct this is embedded in.

 * @member: the name of the member within the struct.

 *

 */

#define container_of(ptr, type, member) ({                     \

       const typeof( ((type *)0)->member ) *__mptr = (ptr);      \

       (type *)( (char *)__mptr - offsetof(type,member) );})

 

cast计算

 

linux-2.6.22.6/include/linux/sched.h(struct task struct的定义也在该文件中)

 

#define while_each_thread(g, t) \

       while ((t = next_thread(t)) != g)

 

include/linux/pid_namespace.h

 

struct pid_namespace {

       struct kref kref;

       struct pidmap pidmap[PIDMAP_ENTRIES];

       int last_pid;

       struct task_struct *child_reaper;

};

 

posted @ 2018-03-13 00:06  云飞风起  阅读(267)  评论(0编辑  收藏  举报