192k views
4 votes
Modify the code below to do the following:

1. Print out the value of GOLDEN_RATIO_PRIME in the simple_init() function.

2. Print out the greatest common divisor of 3,300 and 24 in the simple_exit() function.

simple.c

#include

#include

#include

/* This function is called when the module is loaded. */

int simple_init(void)

{

printk(KERN_INFO "Loading Module\\");

return 0;

}

/* This function is called when the module is removed. */

void simple_exit(void) {

printk(KERN_INFO "Removing Module\\");

}

/* Macros for registering module entry and exit points. */

module_init( simple_init );

module_exit( simple_exit );

MODULE_LICENSE("GPL");

MODULE_DESCRIPTION("Simple Module");

MODULE_AUTHOR("SGG");

1 Answer

6 votes

Answer:

The code is appropriately given below with comments for better understanding

Step-by-step explanation:

#include <linux/init.h>

#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/hash.h>

#include <linux/gcd.h>

#include <asm/param.h>

#include <linux/jiffies.h>

/* This function is called when the module is loaded. */

static int simple_init(void)

{

printk(KERN_INFO "Loading Module\\");

printk(KERN_INFO "These are the HZ: %d\\", HZ);

printk(KERN_INFO "These are the jiffies: %lu\\", jiffies);

printk(KERN_INFO "Golden Ratio is: %lu\\", GOLDEN_RATIO_PRIME);

return 0;

}

/* This function is called when the module is removed. */

static void simple_exit(void) {

printk(KERN_INFO "Removing Module");

unsigned long a = gcd(3300, 24);

printk(KERN_INFO "Greatest Common Denominator between 3,300 and 24 is: %lu\\", a);

printk(KERN_INFO "These are the jiffies: %lu\\", jiffies);

}

/* Macros for registering module entry and exit points. */

module_init( simple_init );

module_exit( simple_exit );

MODULE_LICENSE("GPL");

MODULE_DESCRIPTION("Simple Module");

MODULE_AUTHOR("SGG");

User Chuckedw
by
6.9k points