标签:
一、进程控制块(PCB)结构
进程控制块(PCB)是系统为了管理进程设置的一个专门的数据结构。系统用它来记录进程的外部特征,描述进程的运动变化过程。同时,系统可以利用PCB来控制和管理进程,所以说,PCB(进程控制块)是系统感知进程存在的唯一标志。
Linux系统的PCB包括很多参数,每个PCB约占1KB多的内存空间。用于表示PCB的结构task_struct简要描述如下:
include/linux/sched.h
struct task_struct {
volatile long state;
struct thread_info *thread_info;
atomic_t usage;
unsigned long flags;
unsigned long ptrace;
int lock_depth;
int prio, static_prio;
struct list_head run_list;
prio_array_t *array;
unsigned long sleep_avg;
long interactive_credit;
unsigned long long timestamp;
int activated;
unsigned long policy;
cpumask_t cpus_allowed;
unsigned int time_slice, first_time_slice;
struct list_head tasks;
struct list_head ptrace_children;
struct list_head ptrace_list;
struct mm_struct *mm, *active_mm;
...
struct linux_binfmt *binfmt;
int exit_code, exit_signal;
int pdeath_signal;
...
pid_t pid;
pid_t tgid;
...
struct task_struct *real_parent;
struct task_struct *parent;
struct list_head children;
struct list_head sibling;
struct task_struct *group_leader;
...
struct pid_link pids[PIDTYPE_MAX];
wait_queue_head_t wait_chldexit;
struct completion *vfork_done;
int __user *set_child_tid;
int __user *clear_child_tid;
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;
unsigned long utime, stime, cutime, cstime;
unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
u64 start_time;
...
uid_t uid,euid,suid,fsuid;
gid_t gid,egid,sgid,fsgid;
struct group_info *group_info;
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 fs_struct *fs;
...
struct files_struct *files;
...
unsigned long ptrace_message;
siginfo_t *last_siginfo;
...
};
二、makefile
makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,makefile带来的好处就是——“自动化编译”,一旦写好,只需要一个make命令,整个工程完全自动编译,极大的提高了软件开发的效率。make是一个命令工具,是一个解释makefile中指令的命令工具.
Makefile来告诉make命令如何编译和链接这几个文件。规则是:
1)如果这个工程没有编译过,那么我们的所有C文件都要编译并被链接。
2)如果这个工程的某几个C文件被修改,那么我们只编译被修改的C文件,并链接目标程序。
3)如果这个工程的头文件被改变了,那么我们需要编译引用了这几个头文件的C文件,并链接目标程序。
下面举一个简单的例子:(进度条的实现)
1.vim proc.c写入(进度条的实现)

2、vim Makefile写入

第一行中并没有任何参数,只是在冒号(:)后列出编译中所需的文件,当第一行中的任何文件中更改时,make就知道需要重新编译了。
其中.PHONY意思表示clean是一个“伪目标”,清除 所有 .o文件 ,.o文件就是目标文件
3、执行make指令就可以编译proc.c这个程序
标签:
原文地址:http://www.cnblogs.com/Blog-day/p/MY_Blog_Days-7.html