Question

In: Computer Science

Design a kernel module that creates a /proc file named /proc/jiffies that reports the current value...

  • Design a kernel module that creates a /proc file named /proc/jiffies that reports the current value of jiffies when the /proc/jiffies file is read, such as with the command

    cat /proc/jiffies
    Be sure to remove /proc/jiffies when the module is removed.

Please help with this assignment using C programming and testing in Linux Ubuntu.

Solutions

Expert Solution

#As per the question first, we have to include the head file that is <linux/jiffies.h> as we are using the jiffies from this head file.

/proc:- It is file system that only exist in the kernel memory and used for the pre-process stats.

int proc_init(void)
{
/* creates the /proc/jiffies entry */
        proc_create(PROC_NAME, 0666, NULL, &proc_ops);
        return 0;
}
void proc_exit(void)
{
        /* removes the /proc/jiffies entry */
        remove_proc_entry(PROC_NAME, NULL);
}

In this /proc/jiffies file is removed in the module exit point proc_exit()using the function remove_proc_entry().

size_t proc_read(struct file *file, char __user *usr_buf, size_t count, loff_t *pos)
{
        int rv = 0;
        char buffer[BUFFER_SIZE];
        static int completed = 0;
        
        if (completed) {
                completed = 0;
                return 0;
        }
        
        completed = 1;
        
        rv = sprintf(buffer, "%lu\n", jiffies);
        
        /* copies kernel space buffer to user space usr buf */
        copy_to_user(usr_buf, buffer, rv);
        
        return rv;
}

#In the above code we use the unassigned long in into the variable buffer which exists in the kerenel memory. As /proc/jiffies can be accesed from the user space

#Now we have to make a file and enter this

#Make file

obj-m += jiffies.o
all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

#Output would be like this :


Related Solutions

Create a Python Module named piphash_rainbow.py that Creates a rainbow table named sixdigithash_rainbow.csv that stores all...
Create a Python Module named piphash_rainbow.py that Creates a rainbow table named sixdigithash_rainbow.csv that stores all possible six-digit pins and their corresponding md5, sha1, sha256, and sha512 hashes.
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user for five numbers, and write them, one at a time, on both the screen and into the file. Close the file, then open it again for reading only, and display the contents on the screen. Handle error conditions that may occur. Please Need this to be done in PERL. Thanks
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed cases of covid19. It consists of three columns. The 1st column indicates the names of the provinces, the 2nd column indicates the names of the countries and the 3rd column indicates the numbers of confirmed cases. To do: 1. Define a function that reads, from covid19-3.txt, provinces, countries and confirmed cases in three separate lists. 2. Define a function that iterates through a list...
Design a class named Location for locating a maximal value andits location in a 2-dimensional...
Design a class named Location for locating a maximal value and its location in a 2-dimensional array. The class contains public data fields row, column andmaxValue that store the maximal value and its indices in a 2-dimensional array with row andcolumn as int types andmaxValue as a double typeWrite the following method that returns the location of the largest element in a 2-dimensional array : public static Location locateLargest(double[][] a)The return value is an instance of Location. Write a test...
Design a class named Location for locating a maximal value and its location in a two-dimensional...
Design a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column and maxValue that stores the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two dimensional array: public static location locate Largest(double[][] a) The return value is an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT