操作系统—进程PCB浅析
2019-07-14 06:18发布
生成海报
先了解PCB
进程就是一个运行当中的程序.
程序本来是存储在磁盘的,当我们需要执行它的时候,先把他读取到内存当中,再然后放入到寄存器中,最后让cpu执行程序,这个时候程序就变成了一个进程.
但是进程的生命周期其实不是很长,因为程序运行结束之后,进程的生命周期就终止了.
那么每一个进程肯定都是一个独立的个体,那么每个进程与进程直接肯定都拥有自己独有的一份管理自己的单独的任务结果
.而这个任务结果就是我们今天的PCB.
每个进程运行的时候都会拿到4G的虚拟内存。其中3G是交给用户的,然后剩下的1G内存存储内核的东西。PCB其实就存储在1G的内核系统空间里面。
它其实就是一个task_struct结构体,里面存储着进程的所有信息。
不妨来看看进程task_struct结构体中存的东西吧
struct task_struct {
volatile long state;
unsigned long flags;
intsigpending;
mm_segment_taddr_limit;
volatilelong need_resched;
int lock_depth;
longnice;
unsigned long policy;
struct mm_struct *mm;
int processor;
unsigned long cpus_runnable, cpus_allowed;
struct list_head run_list;
unsigned longsleep_time;
struct task_struct *next_task, *prev_task;
struct mm_struct *active_mm;
struct list_headlocal_pages;
unsigned int allocation_order, nr_local_pages;
struct linux_binfmt *binfmt;
int exit_code, exit_signal;
intpdeath_signal;
unsigned longpersonality;
intdid_exec:1;
pid_tpid;
pid_tpgrp;
pid_t tty_old_pgrp;
pid_tsession;
pid_t tgid;
intleader;
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_value;
struct timer_listreal_timer;
struct tmstimes;
unsigned longstart_time;
longper_cpu_utime[NR_CPUS],per_cpu_stime[NR_CPUS];
unsignedlong 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_tcap_effective, cap_inheritable, cap_permitted;
int keep_capabilities:1;
struct user_struct *user;
struct rlimit rlim[RLIM_NLIMITS];
unsigned shortused_math;
charcomm[16];
int link_count, total_link_count;
struct tty_struct*tty;
unsigned int locks;
struct sem_undo*semundo;
struct sem_queue *semsleeping;
structthread_struct thread;
struct fs_struct *fs;
struct files_struct *files;
spinlock_t sigmask_lock;
struct signal_struct *sig;
sigset_t blocked;
struct sigpendingpending;
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;
void *journal_info;
};
每一个进程都需要4G的虚拟内存,而物理内存就那么点,计算机当中有成千上万的进程,那么这些
进程都存自己的PCB,物理内存其实就只有那么一点,那么这些巨大数量的PCB是怎么存储的呢?
我们可能需要了解一下物理内存和虚拟内存的关系
接下一章:
物理内存与虚拟内存
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮