没有合适的资源?快使用搜索试试~ 我知道了~
首页linux系统调用可视化 操作系统课程设计 实验报告
资源详情
资源评论
资源推荐
操作系统课程设计
系统调用过程可视化
实验目的:
完成 linux 的系统调用过程的可视化,展示执行过程,使用 printk 函数实现。达到可视化
的效果。
实现思路:
进程的创建
获得创建信息
进程的撤销
获得撤销信息
利用系统调用在内核初始化函数 start_kernel 中添加 prink 函数,并且在 start_kernel 函数
调用的子函数中也添加 printk 函数以便在系统初始化时打印出各个函数的调用过程。
关于系统调用的跟踪需要使用 strace,为了更能深入的了解系统调用,我们新建自己的系
统调用,并且添加到内核中,我们可以通过编写程序调用自己的系统调用来验证添加是否
成功。
准备工作:
实验环境:ubuntu12.04 ,内核版本 3.2.28
重新编译内核:
Apt-get update
Apt-get upgrade
1.到 kernel.org 上下载内核源代码,
[html]view plain copy
1. sudocp~/下载/linux-3.2.28.tar.bz2/usr/src
[html]view plain copy
1. cd/usr/src
2. tarjxvflinux-3.2.28.tar.bz2
2.因为进行内核配置的时候需要用到 menuconfig,因此需要首先下载
执行
[plain]view plain copy
1. sudoapt-getinstallncurses-devel
3.因为 ubuntu 自己集成了 make,所以安装好 menuconfig 之后就可以直接进行编译了
执行
[plain]view plain copy
1. makemrproper
2. makelocalmodconfig
3. makemenuconfig
会打开 menuconfig 的配置界面,根据自己的需要更改内核配置即可
4.配置好内核后开始正式编译了,依次执行下面的命令即可
[plain]view plain copy
1. make-j4//j4 是指四线程的意思。这样编译的快,大概需要 20 分钟左右吧››
2. makemodules
3. makemodules_install
4. makeinstall
因为在修改内核源代码之后必须重新编译和加载内核才能使修改后的内核工作所以熟悉内
核编译的步骤是十分必须的。
Linux 下 ftrace 的使用:
下面着重介绍 trace event 的使用,因为在以后的工作中会多次使用到对特定系统调用以及
事件的跟踪,下述资料来自杨老师所发的 ftrace 相关资料。
Trace Events (UserspaceAPI)
We’re in user space now, so you can leave the kernel source directory, but you do need
to be root and you may need to mount a file system. This is because some distributions
(like Ubuntu) have an allergy to debugging (seriously, they even disable things likegdb -
p).
Try and change intothe/sys/kernel/debug/tracingdirectory.
# cd /sys/kernel/debug/tracing
If this fails, you’llneed to mount thedebugfsfilesystem and try again.
# mount -t debugfs none /sys/kernel/debug
# cd /sys/kernel/debug/tracing
With that done, weshould make sure tracing is enabled.
# cat tracing_enabled
1
If that’s 0, enable it:
# echo 1 > tracing_enabled
So we’ve enabledtracing, but what can we trace? Trace events are exposed in the
eventssub-directory in two levels, the first is the subsystem and the second are thetrace
events themselves. Since in my last blog post we were looking at tracingforks, it would
begreat if there were trace events for doing just that. This is where it helps tobe able
togit greparound the kernel source and recognise trace events, so you at least know
theright subsystem name; and it turns out that theschedsubsystem has exactly the
events wewanted.
deathspank tracing# ls events/sched
enable sched_process_exit/ sched_stat_sleep/
filter sched_process_fork/ sched_stat_wait/
sched_kthread_stop/ sched_process_free/ sched_switch/
sched_kthread_stop_ret/ sched_process_wait/ sched_wait_task/
sched_migrate_task/ sched_stat_iowait/ sched_wakeup/
sched_pi_setprio/ sched_stat_runtime/ sched_wakeup_new/
sched_process_forksounds exactly right, if you look at it, it’s a directory thatcontains four
files:enable,filter,formatandid. I bet you canguess how to enable fork tracing, but if not:
# cat events/sched/sched_process_fork/enable
0
# echo 1 > events/sched/sched_process_fork/enable
Pretty painless, sogo ahead and run a few things, and turn the tracing off again when
you’re done.
# echo 0 > events/sched/sched_process_fork/enable
Now let’s look at theresult of our trace; recall that every trace event comes with a
freeprintk()of formattedoutput? We can find the output from those in the top-
leveltracefile.
# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |
zsh-2667 [001] 6658.716936: sched_process_fork: comm=zsh pid=2667
child_comm=zsh child_pid=2748
So for each processfork, we get the parent and child process ids along with the process
name.Pretty much exactly what we want!
内核模块编译和加载方法:
资料来自杨老师的 ppt
How to Create, Compile, Load Linux LKM Loadable Kernel Modules
Suppose we want to add some extra functionality in the Linux kernel.
So the first idea that strikes the mind is to enhance the kernel by adding more code to it,
compiling the code and getting the new kernel up.
But this process has the following drawbacks among several others:
The added code adds to the size of kernel permanently.
The whole kernel needs to be compiled again for the changes to get compiled.
This means that machine needs to be rebooted for changes to take affect.
The solution to above problems is the concept of LKMs.
LKM stands for Loadable kernel modules (LKM). As the name suggests LKMs are the
modules that can be directly loaded in kernel at run time.
The loadable kernel module overcomes all the above mentioned shortcomings.
The module can be compiled separately
The module can be loaded onto kernel at run time without having the machine to reboot.
The module can be unloaded anytime and hence no permanent affect on kernel size.
How to Create LKMs
Lets create a basic loadable kernel module.
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Welcome.....\n");
return 0;
}
剩余22页未读,继续阅读
boyang93
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 27页智慧街道信息化建设综合解决方案.pptx
- 计算机二级Ms-Office选择题汇总.doc
- 单链表的插入和删除实验报告 (2).docx
- 单链表的插入和删除实验报告.pdf
- 物联网智能终端项目设备管理方案.pdf
- 如何打造品牌的模式.doc
- 样式控制与页面布局.pdf
- 武汉理工Java实验报告(二).docx
- 2021线上新品消费趋势报告.pdf
- 第3章 Matlab中的矩阵及其运算.docx
- 基于Web的人力资源管理系统的必要性和可行性.doc
- 基于一阶倒立摆的matlab仿真实验.doc
- 速运公司物流管理模式研究教材
- 大数据与管理.pptx
- 单片机课程设计之步进电机.doc
- 大数据与数据挖掘.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0