添加系统调用实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、构建基本的实验环境

基本实验环境与前提条件

Windows7 、Word 2010、Vmware WorkStation 、AdobeReader

ReadHatLinux ,gcc,vi

Linux内核[虚拟机的安装及使用

将Linux 内核源代码及配置文件传送给虚拟机上的Red Hat Linux 系统

配置网络时遇到这个问题,

Determining IP information for eth0... failed; no link present. Check cable 、

通过查找资料发现是系统的Bug,

解决方法如下:

到/etc/sysconfig/network-scripts/ifcfg-eth0

在文件最后一行中加入

check_link_down () {

return 1;

}

另外如果存在/etc/sysconfig/networking/profiles/default/ifcfg-eth0 文件,则同样在其中加入这一段东西即可,然后重启系统。

设置网络为DHCP,重新启动就可以,啦,直接上图

最后将内核代码下载到/root目录下

\

二、Linux 内核编译、配置与调试

内核配置与编译

、解压内核源代码文件

tar -zxf

、解压后如下

、拷贝linux,命名为-r linux

、移动到根目录,替换掉.config

、进入目录,配置和编译内核模块

make oldconfig

{

make dep

make clean

make bzImage

make modules

内核安装与测试

安装内核映像文件、

cp arch/i386/boot/bzImage

/boot/

拷贝和安装Linux系统映射文件,并创建其与系统映射文件之间的符号链接

执行命令make modules_install 以安装可动态加载的内核模块

添加启动项的配置

利用vi编辑器,vi

查看/ 所在的位置,为/dev/sda3

重新启动系统,从自己创建的内核启动系统

启动后查看内核

分别用uname –r,和dmesg查看

三、Linux 系统调用添加与实现

在内核增加系统调用

结构体struct srz_rusage可声明如下:.

struct srz_rusage {

struct timeval ru_utime; /* user time used */

struct timeval ru_stime; /* system time used */

long ru_majflt; /* major page faults */

long ru_minflt; /* minor page faults */

long ru_nswap; /* swaps */

};

添加到下的中

添加的系统调用名称为:

int get_process_usage(pid_t, struct srz_rusage*);

参考的getrusage和sys_getrusage的代码在下面

分析getrusage()和sys_getrusage()的源代码

1)数据结构rusage 在头文件中定义。

struct rusage {

struct timeval ru_utime; /* user time used */》

struct timeval ru_stime; /* system time used */

long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */

long ru_majflt; /* page faults */

long ru_nswap; /* swaps */

long ru_inblock; /* block input operations */

long ru_oublock; /* block output operations */

long ru_msgsnd; /* messages sent */

long ru_msgrcv; /* messages received */

long ru_nsignals; /* signals received */

long ru_nvcsw; /* voluntary context switches */

long ru_nivcsw; /* involuntary " */

};

2)函数getrusage()的作用是获取系统资源使用情况。

/*

* It would make sense to put struct rusage in the task_struct,

* except that would make the task_struct be *really big*. After

* task_struct gets moved into malloc'ed memory, it would

* make sense to do this. It will make moving the rest of the information '

* a lot simpler! (Which we're not doing right now because we're not

* measuring them yet).

*

* This is SMP safe. Either we are called from sys_getrusage on ourselves * below (we know we aren't going to exit/disappear and only we change our * rusage counters), or we are called from wait4() on a process which is * either stopped or zombied. In the zombied case the task won't get

* reaped till shortly after the call to getrusage(), in both cases the

* task being examined is in a frozen state so the counters won't change. *

* FIXME! Get the fault counts properly!

*/

int getrusage(struct task_struct *p, int who, struct rusage *ru)

{

struct rusage r;

memset((char *) &r, 0, sizeof(r));

switch (who) {

case RUSAGE_SELF:

= CT_TO_SECS(p->;

= CT_TO_USECS(p->;

= CT_TO_SECS(p->;

:

= CT_TO_USECS(p->;

= p->min_flt;

= p->maj_flt;

= p->nswap;

break;

case RUSAGE_CHILDREN:

= CT_TO_SECS(p->;

= CT_TO_USECS(p->;

= CT_TO_SECS(p->;

= CT_TO_USECS(p->;

相关文档
最新文档