In this assignment you will write a LKM for the Linux kernel that displays the f
ID: 3605031 • Letter: I
Question
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.
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, describe the basic purpose of each of the module functions you had to implement.
• For struct task_stuct (see Section 4), describe each element of struct that you used. Include which line number it was dened on.
• For list.h (see Section 4), describe each function/macro you used to manipulate the list of executing processes (tasks).
abhinav@abhinav-HP-ProBook-4520s:-/Desktops sudo insmod /Process-1.ko inp_pid-3500 abhinav@abhinav-HP-ProBook-4520s:-/DesktopsExplanation / Answer
Here is the code for above scenario:
#include<stdio.h>
void DFS(int);
int G[10][10],visited[10],n; //n is no of vertices and graph is sorted in array G[10][10]
void main()
{
int i,j;
printf("Enter number of vertices:");
scanf("%d",&n);
//read the adjecency matrix
printf(" Enter adjecency matrix of the graph:");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);
//visited is initialized to zero
for(i=0;i<n;i++)
visited[i]=0;
DFS(0);
}
void DFS(int i)
{
int j;
printf(" %d",i);
visited[i]=1;
for(j=0;j<n;j++)
if(!visited[j]&&G[i][j]==1)
DFS(j);
}