Question: Summary: In this homework, you will be implement a kernel module that uses Linux data structures to display details about the processes executing in the
Summary: In this homework, you will be implement a kernel module that uses Linux data structures to display details about the processes executing in the kernel.
1 Background
The kernel is a program that is the core of a computer's operating system, with complete control over everything in the system. It is the ??rst program loaded on start-up. It performs tasks such as running processes, handling interrupts and all other handling that happens behind the scenes in kernel space whereas everything user does is executed in user-space. This separation prevents user data and kernel data from interfering with each other and causing instability and slowness.
Kernel modules are pieces of code which provide functionality to the kernel. The word ??Loadable?? is pre??xed to kernel module to show that it eases the process of integrating the module with the kernel. Generally, if any functionality is to be provided in the kernel, it has to incorporated by compiling the kernel with the proposed changes. Loadable Kernel Modules (LKM) ease that process by providing the facility to integrate itself within the kernel instead of requiring kernel re-compilation. For information on creating
LKMs, see Operating System Concepts page 96 or www.tldp.org/HOWTO/html_single/Module-
HOWTO/#AEN73. You will need to use a so-called "make??le" to manage the compilation of your module.It will not be possible to use NetBeans to develop your code.
In this assignment you will write a LKM for the Linux kernel that displays the certain details of the processes (along with its parent and child) executing in the kernel. As an important step to implementing the program, you should review the section on include ??les to get an idea of what functionality is available. From there, you may choose to outline your program in pseudocode, and then convert it into actual source code, while reading the documentation for any functions you used. Expect that a signi??cant part of your time on this assignment will be spent reading/researching/understanding LKM documentation and reviewing kernel source code ??les (linux/sched.h, and linux/list.h). The source code should be relatively short. For kernel source code, visit www.kernel.org/. Any lines numbers mentioned in this document refer to Linux 4.9.6; please reference that version as well.
This document is separated into ??ve sections: Background, Requirements, Make??les, Include Files, and Submission. You have almost ??nished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. In Include Files, we discuss several header ??les that include functionality related to ??le and directory manipulation. Lastly, Submission discusses how your source code should be submitted on BlackBoard.
2 Requirements [35 points total]
In this assignment you will write a LKM for the Linux kernel that displays the following details for all the processes whose PID is greater than an integer given by the user as a module parameter: [25 points]
PROCESS NAME PID STATE PRIORITY
STATIC-PRIORITY NORMAL-PRIORITY
1
As shown below, the PID is given as arguments while inserting the module in the kernel.
The next screenshot shows the required details for a process, its child processes (may have 0 or more), and its parent process. You are expected to keep a similar format (not an exact one) for your output which is readable. Your programs must compile and run under Xubuntu (or another variant of Ubuntu) 16.04.
2.1 Writeup [10 points]
You are to provide a short write up that illustrates what you found when looking at the Linux source ??les and documentation. Include the following:
For your main source ??le, list each function that you de??ned and describe its purpose. For each header ??le (except linux/module.h), document each function/macro/struct used:
?? Functions: Include the function's signature, what ??le/line it is de??ned, and a description (include parameters and return values).
?? Macro: same as function. ?? Struct: Indicate what ??le/line it is de??ned, and document each of the attributes used.
2
The purpose of the write up is show the ??research?? you did when creating your program. Do not quote (or paraphrase) any 3rd party documentation - use your own words and understanding. Although there is no mandatory format, please be professional. Your document should be self-contained, well styled (e.g., no comic sans, random font sizes), and readable (e.g., no spelling or grammar errors).
3 Make??les
A make??le is a ??le containing a set of directives used with the make tool to automate the build process for a ??le or a set of ??les. For example, assume we have a huge codebase that has hundreds of ??les with lots of dependencies between them. Generally, we would compile each ??le, generate an object ??le and link all the object ??les together to generate an executable. Even if there is a small change in one of the ??les, we would have to recompile and link them which is quite a cumbersome and ine??cient process. Using Make??les, you can ensure that only the ??les that have been modi??ed since the last build and those which are dependent on the changed ??les are the ones which are compiled.
make uses the timestamp on a ??le to check if the ??le has been modi??ed and whether it has to be recompiled or not. If you have a "make??le" in your directory which speci??es the rules for compiling the ??les (including the dependencies), all you have to do is run "make". If you want to run only speci??c rules, you can specify using "make
target: dependencies system command(s)
where target is usually the name of a ??le that is generated by a program like executable or object ??les; a dependency (also called prerequisite) is a ??le that is used as input to create the target; the system command(s) (also called recipe) is an action that make carries out. Note the use of meaningful indentation in specifying commands; also note that the indentation must consist of a single
The above snapshot speci??es that the target edit depends on main.o and display.o for its build, which further depend on their source ??les main.c and display.c respectively. For executing above, we need to have all the above ??les along with Make??le in the same directory. When we execute the command makein the same directory, the make tool tries to build the target edit by ??guring out whether any dependencies have been modi??ed since their last build and if so, builds those desired dependencies and produces the targetedit. For more information on make visit GNU Make??le
For this assignment writing a make??le would take away the hassle of specifying the arguments while building the loadable module. Just writing make would ensure that the LKM built is the latest one.
3
4 Include Files To complete this assignment, you may ??nd the following include ??les useful:
linux/sched.h: De??nes processes and their associated details.?? Useful types:
? struct task_struct - A structure to contain process details (see line 1475) linux/sched/signal.h: Iterates through proccesses.
?? Useful macros: ? for_each_process - A macro to loop over each currently running process (see line 503)
linux/list.h: Implements a circular-linked list in C language which could be used to fetch the child processes.
?? Useful types: ? struct list_head
?? Useful functions:? list_for_each
? list_entry Note that you are not limited to using these functions, nor are you required to use all of them.
5 Submission
The submission for this assignment has two parts: a write up, and the source code (optional: include the Make??le which compiles the module). The ??le(s) should be attached to the homework submission link on BlackBoard.
Writeup: For this assignment, you should provide a write up as discussed previously in PDF format.
Source Code: Please name your ??le(s) as "LastNameLKM.zip" (e.g. "JainLKM.zip"), which should contain a ??.c?? of the same name (e.g., JainLKM.c), a ??.pdf?? of the same name (JainLKM.pdf), and optionally a make??le.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
