Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm new to linux world, I need to do these steps :

1) compile this module (hello.c):

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>

struct proc_dir_entry *file;

ssize_t proc_read(char *buffer, char **buffer_location,
          off_t offset, int buffer_length, int *eof, void *data) {
  int len = 0; 

  if (offset > 0) {
    *eof = 1;
    return len;
  }

  len = sprintf(buffer, "Hello, World!\n");
  return len;
}


int init_module(void) {
  int rv = 0;
  file = create_proc_entry("hello", 0644, NULL);
  file->read_proc = proc_read;
  file->mode = S_IFREG | S_IRUGO;
  file->uid = 0;
  file->gid = 0;
  file->size = 37;

  if (file == NULL) {
    rv = -ENOMEM;
    remove_proc_entry("hello", NULL);
    printk("Problem with the module!\n");
  } else {
    printk("Module loaded!\n");
  }

  return rv;
}

void cleanup_module(void) {
  remove_proc_entry("hello", NULL);
  printk("Module unloaded!\n");
}

MODULE_LICENSE("GPL");

2) This module should create a file /proc/hello (where I found this file ?) when readed, this file should present the follow message: 'Hello World!'.

3) Change the module above to show the PID instead the 'Hello World!'message. Compile and see its working.

I'm folling this tutorial, but nothing so far.

Any tip, any help will be very appreciated.

share|improve this question
Please detail your problem more precisely: how did you try to compile it? what errors are you getting? and so on... – m0skit0 Oct 11 '11 at 14:43
I don't know how to do that, how I should compile a module ? – Valter Henrique Oct 11 '11 at 17:44

closed as not a real question by RedGrittyBrick, Diago Oct 11 '11 at 18:49

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

Browse other questions tagged or ask your own question.