我编写了一个简单的proc文件,以从内核获取秒数的滴答声,但是当我运行cat命令时,我得到秒数的滴答声,但是循环永远不会结束。 linux版本4.18.14
static ssize_t proc_read_jiffies(struct file *fp, char *buf, size_t len, loff_t *offset)
{
static int finished = 0;
if (finished){
finished = 0;
return (int)0;
}
finished=1;
int lenr;
//lenr = sprintf(buf, "jiffies = %ld \n",jiffies);
time = ( jiffies - jiffies_start )/HZ;
sprintf(buf,"time elapsed = %d \n",time);
return (int)strlen(buf);
}
static struct file_operations jiffiesRead =
{
.owner = THIS_MODULE,
.read = proc_read_jiffies,
};
static int init_procfs_example(void)
{
jiffies_file = proc_create("jiffies",
0666, NULL,
&jiffiesRead);
jiffies_start = jiffies;
/* everything OK */
printk(KERN_INFO "%s %s initialised\n",MODULE_NAME, MODULE_VERS);
return 0;
}