I'm trying to create a kernel module that will create a /dev/process_list character device. If a read() call is made on my character device, the kernel module must return information on all currently running processes, namely: their process ID, their parents PID, which CPU it's running on, and the current state of the process.
Currently, my idea for the user space code is as follows:
#include <stdio.h>#include <errno.h>int main(){ char* buffer = (char*) malloc(sizeof(char*)); FILE* fd; fd = open("/dev/process_list", O_RDONLY); if(!fd){ printf("Failure\n"); exit(EXIT_FAILURE); } while( /*no more inputs being read in*/ ){ char bytes_read = read(fd, buffer, buffer_length); } close(fd); return 0;}
However, I'm new to kernel modules and unsure of how to make this. How can I do it?