有一段程序供其执行(不一定是一个进程所专有的)
有自己的专用系统堆栈空间
有进程控制块(task_struct)
有专用的用户空间。
只具备前三条的称为线程,如果完全没有用户空间称为内核线程,共享用户空间的称为用户线程。
进程控制块结构:
struct
task_struct {
volatile long state;0,running 进程可以被调度执行而成为当前进程,1
interrupt当前进程为睡眠状态,2 uninterrupt进程为深度睡眠状态(不响应软中断),4
zombie该进程已经去世,但是户口未被注销,8 stopped,进程挂起
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 has_cpu, processor;
unsigned long cpus_allowed;
struct list_head run_list;
unsigned long sleep_time;
struct task_struct *next_task, *prev_task;
struct mm_struct *active_mm;
struct linux_binfmt *binfmt;应用程序的文件格式
int exit_code, exit_signal;详见系统调用exit和wait4
int pdeath_signal;
unsigned long personality;由于版本不同导致程序有个性
int dumpable:1;
int did_exec: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 semaphore *vfork_sem;
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;
struct tty_struct *tty;
unsigned int locks;
struct sem_undo *semundo;
struct sem_queue *semsleeping;
struct thread_struct thread;
struct fs_struct *fs;
struct files_struct *files;
spinlock_t sigmask_lock;
struct signal_struct *sig;
sigset_t blocked;
struct sigpending pending;
unsigned long sas_ss_sp;
size_t sas_ss_size;
int (*notifier)(void *priv);
void *notifier_data;
sigset_t *notifier_mask;
u32
parent_exec_id;与进程组有关
u32
self_exec_id;与进程组有关
spinlock_t alloc_lock;
};