作者: sunmoon
在linux 中每一個進程都由task_struct 數據結構來定義
她是對進程控制的唯一手段也是最有效的手段
當我們調用fork() 時
並把新的進程插入到進程樹中
調度(在linux 中任務和進程是同一概念)的關鍵
我們的理論推一下它的結構
因為每一個PCB都是這樣的
打開/include/linux/sched
struct task_struct {
/* these are hardcoded
這裡是一些硬件設置對程序原來說是透明的
還是可中斷等信息
與普通進程在內存存放的位置不同
volatile long state; /*
unsigned long flags; /* per process flags
int sigpending;
mm_segment_t addr_limit; /* thread address space:
*/
struct exec_domain *exec_domain;
long need_resched;
/* various fields */
count 是 計數器 priorrity 是優先級
long counter;
long priority;
cycles_t avg_slice;
/* SMP and runqueue state */
為多處理機定義的變量
int has_cpu;
int processor;
int last_processor;
int lock_depth;
/* Lock depth
為了在進程樹中排序
struct task_struct *next_task
struct tas
/* task state */
定義可 task 運行的狀態
struct linux_binfmt *binfmt;
int exit_code
int pdeath_signal; /* The signal sent when the parent dies */
/* 定義可進程的用戶號
unsigned long personality;
int dumpable:
int did_exec:
pid_t pid;
pid_t pgrp;
pid_t tty_old_pgrp;
pid_t session;
/* boolean value for session group leader */
是不是進程組的頭文件
int leader;
/*
* pointers to (original) parent process
* older sibling
* p
*/
父子進程的一些指針
struct task_struct *p_opptr
/* PID hash table linkage
在調度中用的一些hash 表
struct task_struct *pidhash_next;
struct task_struct **pidhash_pprev;
/* Pointer to task[] array linkage
struct task_struct **tarray_ptr;
struct wait_queue *wait_chldexit; /* for wait
struct semaphore *vfork_sem; /* for vfork() */
unsigned long policy
unsigned long it_real_value
進程的性質因為實時進程與普通進程的調度算法不一樣所以應有變量區分
下面是進程的一些時間信息
unsigned long it_real_incr
struct timer_list real_timer;
struct tms times;
unsigned long start_time;
long per_cpu_utime[NR_CPUS]
/* mm fault and swap info: this can arguably be seen as either mm
thread
內存信息
unsigned long min_flt
int swappable:
/* process credentials */
uid_t uid
gid_t gid
int ngroups;
gid_t groups[NGROUPS];
kernel_cap_t cap_effective
struct user_struct *user;
以下英文注釋很清楚
/* limits */
struct rlimit rlim[RLIM_NLIMITS];
unsigned short used_math;
char comm[
/* file system info */
int link_count;
struct tty_struct *tty; /* NULL if no tty */
/* ipc stuff */
struct sem_undo *semundo;
struct sem_queue *semsleeping;
/* tss for this task */
struct thread_struct tss;
/* filesystem information */
struct fs_struct *fs;
/* open file information */
struct files_struct *files;
/* memory management info */
struct mm_struct *mm;
/* signal handlers */
spinlock_t sigmask_lock; /* Protects signal and blocked */
struct signal_struct *sig;
sigset_t signal
struct signal_queue *sigqueue
unsigned long sas_ss_sp;
size_t sas_ss_size;
};
在分析完 這個結構之後
malloc(
拷貝一些變量
我認為不能不想)
有幾種形勢
進行遍歷
的fifo機制不用)linux 是怎樣保證了高效呢?如果把最大線成數修改
待續
From:http://tw.wingwit.com/Article/program/Oracle/201311/18993.html