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.