You are required to develop a Linux kernel loadable module c

You are required to develop a Linux kernel loadable module called las02.ko. The module should have a parameter pid_input. When the module is loaded it should print to the kernel log the following information of the process with pid that matches to the parameter: process id parent process id command line system time user time priority userid When the module is unloaded, it should display the same information for the parent process of the corresponding process. Test the module and make sure you handle all cases, exceptions and cover possible user mistakes. You must submit a compressed tile that contains: kernel module files Print screen of the sample run Output of the kernel log output of the \"ps\" command and user id to support your answer Rules for Delivery: Write your name, ID, semester, course number, and assignment number in the source file. Follow a reasonable coding and documentation style to make your code readable, with proper comments and indentation. Compress the files in one archive named: name_id_las1.zip and send it to me. Any violation of the above points means some marks will be deducted.

Solution

#include<linux/version.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>
#include<linux/pid.h>

#define PARENT 0
#define CHILD 1

int pid_input = -1;
module_param(pid_input,int,0);// Read the parameter from command line and assign to pid_input variable

struct task_struct *child = NULL; // pointer to structure of task_struct to store the address of given process id
struct task_struct *parent = NULL;//pointer to structure of task_struct to store the address of given process id

void print(int process)
{
       if(process == PARENT)// printing the requirements using printk
       {
               printk(\"OUR_MODULE:: process_id = %d, parent_process_id = %d, system_time = %ld, user_time = %ld, priority = %ld, user_id = %ld\ \",child->pid, child -> p_pptr -> pid, child -> stime, child -> utime, child -> priority, child -> uid);
       }
      
       else if(process == CHILD)
       {
               printk(\"OUR_MODULE:: process_id = %d, parent_process_id = %d, system_time = %ld, user_time = %ld, priority = %ld, user_id = %ld\ \",parent->pid, parent -> p_pptr -> pid, parent -> stime, parent -> utime, parent -> priority, parent -> uid);
       }
}
int init_mod(void) // Function which executes during insertion of module
{
   if(pid_input == -1)
   {
           printk(\"OUR_MODULE:: pid_input is not passed as an argument...\ \");
           return 0;
   }  
   child = pid_task(find_vpid(pid_input),PIDTYPE_PID);// Traversing and getting the correspoding task_struct structure for given process id
  
   if(child == NULL)// If the process with given pid doesnot exist
   {
           printk(\"OUR_MODULE:: process with pid = %d doesnot exist\",pid_input);
           return 0;
   }
  
   parent = child -> p_pptr; // Getting the parent task_struct from child task_struct
   print(CHILD);
   return 0;

}

void cleanup_mod(void)
{

   if(pid_input == -1)
   {
           printk(\"OUR_MODULE:: pid_input is not passed as an argument...\ \");
           return;
   }
  
   if(parent == NULL)
   {
           printk(\"OUR_MODULE:: process with pid = %d doesnot exist\",pid_input);
           return;
   }
  
   print(PARENT);// call the printing function
  
   return 0;

}


module_init(init_mod);// registering the function init_mod so that function executes during the insertion of module
//module_exit(cleanup_mod);

MODULE_AUTHOR(\"MALLESWARA REDDY MULA\");
MODULE_DESCRIPTION(\"Getting the Process info from given process id\");
MODULE_LICENSE(\"GPL\");

 You are required to develop a Linux kernel loadable module called las02.ko. The module should have a parameter pid_input. When the module is loaded it should p
 You are required to develop a Linux kernel loadable module called las02.ko. The module should have a parameter pid_input. When the module is loaded it should p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site