ssize_t and size_t

http://www.delorie.com/gnu/docs/glibc/libc_239.html
Data Type: ssize_t
   This data type is used to represent the sizes of blocks that can be read or written in a single operation. It is similar to size_t, but must be a signed type.

http://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html
— Data Type: size_t
   This is an unsigned integer type used to represent the sizes of objects. The result of the sizeof operator is of this type, and functions such as malloc (see Unconstrained Allocation) and memcpy (see Copying and Concatenation) accept arguments of this type to specify object sizes.
#include <linux/init.h> /* __init and __exit macroses */ #include <linux/kernel.h> /* KERN_INFO macros */ #include <linux/module.h> /* required for all kernel modules */ #include <linux/moduleparam.h> /* module_param() and MODULE_PARM_DESC() */ #include <linux/fs.h> /* struct file_operations, struct file */ #include <linux/miscdevice.h> /* struct miscdevice and misc_[de]register() */ #include <linux/slab.h> /* kzalloc() function */ #include <linux/uaccess.h> /* copy_{to,from}_user() */ #include <linux/init_task.h> //init_task再次定义 #include "proc_relate.h" MODULE_LICENSE("GPL"); MODULE_AUTHOR("Wu Yimin>"); MODULE_DESCRIPTION("proc_relate kernel modoule"); static int proc_relate_open(struct inode *inode, struct file *file) { struct proc_info *buf; int err = 0; buf=kmalloc(sizeof(struct proc_info)*30,GFP_KERNEL); file->private_data = buf; return err; } static ssize_t proc_relate_read(struct file *file, char __user * out,size_t size, loff_t * off) { struct proc_info *buf = file->private_data; /* 你需要补充的代码 */ } static int proc_relate_close(struct inode *inode, struct file *file) { struct buffer *buf = file->private_data; kfree(buf); return 0; } static struct file_operations proc_relate_fops = { .owner = THIS_MODULE, .open = proc_relate_open, .read = proc_relate_read, .release = proc_relate_close, .llseek = noop_llseek }; static struct miscdevice proc_relate_misc_device = { .minor = MISC_DYNAMIC_MINOR, .name = "proc_relate", .fops = &proc_relate_fops }; static int __init proc_relate_init(void) { misc_register(&proc_relate_misc_device); printk(KERN_INFO "proc_relate device has been registered.\n"); return 0; } static void __exit proc_relate_exit(void) { misc_deregister(&proc_relate_misc_device); printk(KERN_INFO "proc_relate device has been unregistered\n"); } module_init(proc_relate_init); module_exit(proc_relate_exit);补充这段代码需要补充的函数部分,使其能编译为内核模块,安装该内核模块后测试程序,运行结果类似如下:Here is parent process,pid = 7329 this is a child,pid is 7330 this is another child,pid is 7331 this is a child,pid is 7333 In thread,pid=7331 tid=7334 thread id=1254224352 this is a child,pid is 7332 this is a child,pid is 7335 ------------------------------------------------------- pid=2616 tgid=2616 comm=sshd sessionid=4 mm=ffff8000fae19000 activeMM=ffff8000fae19000 parent =1971 real_parent=1971 group_leader2616 ------------------------------------------------------- pid=2670 tgid=2670 comm=sshd sessionid=4 mm=ffff8000fa477500 activeMM=ffff8000fa477500 parent =2616 real_parent=2616 group_leader2670 -------------------------------------------------------
05-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值