Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    exchange data from kernel to process

    Hi everybody,

    I really am a newbie in kernel development and I have this question.

    I am developing an application that need to read some informations from the kernel. More specifically these informations regard the TCP part of the kernel.

    I thought I could use the /proc filesystem in order to make the kernel write those informations in a specific file.

    But until now I didn't find a complete guide that explains how to do this.

    In any guide (I can't post URLs), for example, it is said that we need to create a module and when the module is loaded the function create_proc_entry() will be called.

    The problem is that the part of kernel which need to write my informations, is a static part, so I don't need to create that module.
    But in that case, who will call the create_proc_entry? And where do I put all the functions mentioned in the guide then?
    Can you please clarify this to me?



  2. #2
    I have written a simple driver to write content to some user space file.
    Please change this as per your need.

    #include <linux/module.h>  // Needed by all modules
    #include <linux/kernel.h>  // Needed for KERN_INFO
    #include <linux/fs.h>      // Needed by filp
    #include <linux/string.h>
    #include <asm/uaccess.h>   // Needed by segment descriptors
    int init_module(void)
    // Create variables
            struct file *f;
            char buf[128];
            mm_segment_t fs;
            int i;
    // Init the buffer
                    buf[i] = 0;
            printk(KERN_INFO "My module is loaded\n");
    //Open the file
            f = filp_open("/etc/testFile", O_CREAT|O_WRONLY|O_APPEND, 0);
            if(f == NULL)
                    printk(KERN_ALERT "filp_open error!!.\n");
                    // Get current segment descriptor
                    fs = get_fs();
                    // Set segment descriptor associated to kernel space
    // Write to buf
    strcpy(buf,"I love my country");
    // Write to the file
                    f->f_op->write(f, buf, strlen(buf), &f->f_pos);
                    // Restore segment descriptor
    //close the file
            return 0;
    void cleanup_module(void)
                printk(KERN_INFO "My module is unloaded, so now check your new file content\n");
    Your Makefile
    obj-m += module.o
            make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
            make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    Let me know for any issue.
    Barun Parichha

  3. #3
    Hi barunparichha,

    I have solved my problem now, because I modified an already existing proc file, instead of creating a new one.

    Still your module is very useful and rather simple to understand, so I am sure it will come in handy sooner or later.

    Thank you,


  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts