
[英]reading the timestamp from kernel using procfs - where is it stored after reading from kernel?
[英]where will be the output of the user from kernel using procfs?
ssize_t dev_read(struct file *filp,char *buf,size_t count,loff_t *offset)
{
int len = count >= strlen(chr_arr.array) ? strlen(chr_arr.array) : count;
*offset += len;
if (*offset >= strlen(chr_arr.array))
return 0;
if (copy_to_user(buf,chr_arr.array,len))
return -EFAULT;
return len;
}
我想从内核读取一个值并在用户应用程序中使用它,因此我正在使用procfs api从内核读取并在用户空间中使用它。
以上是从内核读取并将其存储在用户缓冲区(buf)中的读取功能。 但是,如果我想从用户应用程序中读取输出,那么将从用户空间中存储的内核中读取值? 有人可以帮我吗?
如果该值在procfs中公开,则您的用户应用程序只需将procfs节点作为文件打开,然后像读取其他任何文件一样读取它。 花哨的东西都在内核中完成。
如果您要编写一个内核组件以向procfs公开某些内容,那么您将需要类似于引用的代码来处理对procfs节点的read()
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.