首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | linux相关 | linux认证 | 下载中心 | 专题
oklinux
 系统管理:中文环境 系统管理 桌面应用 内核技术 Linux基础:安装配置 常用命令 经验技巧 软件应用 Linux数据库:Mysql POSTGRE
 网络管理:网络安全 网络应用 Linux服务器 编程开发:PHP CC++ Python Perl SHELL 嵌入式开发 | PHP基础 PHP技巧 PHP应用 PHP文摘
 首页 linux资讯动态 Linux专题 | 其他Unix Linux解决方案 硬件相关 Linux认证 企业应用 Apache | 相关下载:资料 参考手册 开发工具
 → 当前位置:首页>系统管理>内核技术>正文

Kernel command using Linux system calls

OKLinux www.oklinux.cn 2007-03-28 来源:IBM developerWorks Worldwide 会员收藏 游客收藏


Kernel jiffies

The Linux kernel maintains a global variable called jiffies, which represents the number of timer ticks since the machine started. This variable is initialized to zero and increments each timer interrupt. You can read jiffies with the get_jiffies_64 function, and then convert this value to milliseconds (msec) with jiffies_to_msecs or to microseconds (usec) with jiffies_to_usecs. The jiffies' global and associated functions are provided in ./linux/include/linux/jiffies.h.

Listing 2 provides the third function. This function takes two arguments: a long and a pointer to a long that's defined as __user. The __user macro simply tells the compiler (through noderef) that the pointer should not be dereferenced (as it's not meaningful in the current address space). This function calculates the difference between two jiffies values, and then provides the result to the user through a user-space pointer. The put_user function places the result value into user-space at the location that presult specifies. If an error occurs during this operation, it will be returned, and you'll likewise notify the user-space caller.

For step 2, I update the header files to make room for the new functions in the system call table. For this, I update the header file linux/include/asm/unistd.h with the new system call numbers. The updates are shown in bold in Listing 3.


Listing 3. Updates to unistd.h to make room for the new system calls
	
#define __NR_getcpu		318
#define __NR_epoll_pwait	319
#define __NR_getjiffies		320
#define __NR_diffjiffies	321
#define __NR_pdiffjiffies	322

#define NR_syscalls	323

Now I have my kernel system calls and numbers to represent them. All I need to do now is draw an equivalence among these numbers (table indexes) and the functions themselves. This is step 3, updating the system call table. As shown in Listing 4, I update the file linux/arch/i386/kernel/syscall_table.S for the new functions that will populate the particular indexes shown in Listing 3.


Listing 4. Update the system call table with the new Functions
	
.long sys_getcpu
.long sys_epoll_pwait
.long sys_getjiffies		/* 320 */
.long sys_diffjiffies
.long sys_pdiffjiffies

Note: The size of this table is defined by the symbolic constant NR_syscalls.

At this point, the kernel is updated. I must recompile the kernel and make the new image available for booting before testing the user-space application.

Reading and writing user memory

The Linux kernel provides several functions that you can use to move system call arguments to and from user-space. Options include simple functions for basic types (such as get_user or put_user). For moving blocks of data such as structures or arrays, you can use another set of functions: copy_from_user and copy_to_user. Moving null-terminated strings have their own calls: strncpy_from_user and strlen_from_user

共8页: 上一页 [1] [2] 3 [4] [5] [6] [7] [8] 下一页
上一篇:Novell称微软专利许可观点“强奸民意”   下一篇:Linux and symmetric multiprocessing

收藏于收藏夹】 【评论】 【推荐】 【投稿】 【打印】 【关闭

相关文章
·Linux and symmetric multiprocessing
·通过Linux内核观察/proc/pid/statm
·Linux内核源代码的目录结构简单介绍
·按需对Linux系统内核进行定制和修改
·将驱动及应用软件移植到Linux2.6内核
·全面了解Linux操作系统核心配置文件
·三分钟编译支持NTFS的Linux系统模块
·linux内核启动地址的确定
·ubuntu 6.10 下编译2.6.19内核并安装NVIDIA
·教菜鸟编译自己的内核2.6.19
发表评论
密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。)
站内搜索
阅读排行榜
·基于S3C44B0微处理器的uCl
· 深入理解LINUX内核中文版
·Linux操作系统的内核编译
·Process priority and con
·Linux 2.6内核如何武装Fed
·通过振动向Linux ThinkPad
·主流嵌入式Linux系统下GUI
·推荐:Linux用户态与内核
·用命令行加挂Linux的文件
·Linux系统内核接收以太帧
最新文章
·用Tftp向目标板烧写Linux
·交叉编译Linux内核(2.6.22
·UNIX操作系统的加锁解锁:
·基于2.6.9内核小型Linux系
·Linux系统中使用GCC CPU参
·Linux系统的引导过程详细
·Linux系统的内核初始化过
·Linux系统高手之路 内核编
·Linux高手之内核编译过程
·Linux系统内核模块和驱动
·Linux系统下编译支持NTFS
·Linux系统中用内核KHTTPD
·Linux系统内核分析 使用GD
·Linux操作系统的内核解读
·通过Linux系统的内核观察/

设为首页 - 加入收藏 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyright © 2007 All rights reserved OKLinux.Cn 版权所有
合作联系 QQ:18743986 Email:arlan8005#163.com