user3458454
user3458454

Reputation: 321

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;
}

I want to read a value from kernel and use it in a user application, so i am using procfs api to read from the kernel and use it in a user space.

The above is the read function to read from the kernel and store it in a user buffer(buf). But If i want to read the output from user application then where will be value read from kernel stored in a user space ?? could someone help me in this ??

Upvotes: 1

Views: 73

Answers (1)

user3553031
user3553031

Reputation: 6214

If the value is exposed in procfs, your user application just needs to open the procfs node as a file and read it like any other file. The fancy stuff's all done in the kernel.

If you're trying to write a kernel component that exposes something to procfs, then you'll need something similar to the code that you quoted to handle read() calls to the procfs node.

Upvotes: 0

Related Questions