进程在操作系统中都有一个户口,用于表示这个进程。这个户口操作系统被称为PCB(进程控制块),在linux中具体实现是 task_struct数据结构,它记录了一下几个类型的信息:1.状态信息,例如这个进程处于可执行状态,休眠,挂起等。2.性质,由于unix有很多变种,进程有自己独特的性质。3.资源,资源的链接比如内存,还有资源的限制和权限等。4.组织,例如按照家族关系建立起来的树(父进程,子进程等)。下面是这一个数据结构
[cpp] view plain copy- struct task_struct {
-
-
-
- volatile long state;
- unsigned long flags;
- int sigpending;
- mm_segment_t addr_limit;
-
-
-
- struct exec_domain *exec_domain;
- volatile long need_resched;
- unsigned long ptrace;
-
- int lock_depth;
-
-
-
-
-
-
- long counter;
- long nice;
- unsigned long policy;
- struct mm_struct *mm;
- int processor;
-
-
-
-
-
-
-
-
- unsigned long cpus_runnable, cpus_allowed;
-
-
-
-
- struct list_head run_list;
- unsigned long sleep_time;
-
- struct task_struct *next_task, *prev_task;
- struct mm_struct *active_mm;
- struct list_head local_pages;
- unsigned int allocation_order, nr_local_pages;
-
-
- struct linux_binfmt *binfmt;
- int exit_code, exit_signal;
- int pdeath_signal;
-
- unsigned long personality;
- int did_exec:1;
- unsigned task_dumpable:1;
- pid_t pid;
- pid_t pgrp;
- pid_t tty_old_pgrp;
- pid_t session;
- pid_t tgid;
-
- int leader;
-
-
-
-
-
- struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
- struct list_head thread_group;
-
-
- struct task_struct *pidhash_next;
- struct task_struct **pidhash_pprev;
-
- wait_queue_head_t wait_chldexit;
- struct completion *vfork_done;
- unsigned long rt_priority;
- unsigned long it_real_value, it_prof_value, it_virt_value;
- unsigned long it_real_incr, it_prof_incr, it_virt_incr;
- struct timer_list real_timer;
- struct tms times;
- unsigned long start_time;
- long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
-
- unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
- int swappable:1;
-
- uid_t uid,euid,suid,fsuid;
- gid_t gid,egid,sgid,fsgid;
- int ngroups;
- gid_t groups[NGROUPS];
- kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
- int keep_capabilities:1;
- struct user_struct *user;
-
- struct rlimit rlim[RLIM_NLIMITS];
- unsigned short used_math;
- char comm[16];
-
- int link_count, total_link_count;
- struct tty_struct *tty;
- unsigned int locks;