Operating System Design Process Control

Assignment

Design a kernel module that iterates through all tasks in the system using the
for each process() macro. In particular, output the task command, state,
and process id of each task. (You will probably have to read through the
task struct structure in <linux/sched.h> to obtain the names of these
fields.) Write this code in the module entry point so that its contents will appear
in the kernel log buffer, which can be viewed using the dmesg command. To
verify that your code is working correctly, compare the contents of the kernel
log buffer with the output of the following command, which lists all tasks in
the system:
ps -el
The two values should be very similar. Because tasks are dynamic, however, it
is possible that a few tasks may appear in one listing but not the other.
Part II—Iterating over Tasks with a Depth-First Search Tree
The second portion of this project involves iterating over all tasks in the system
using a depth-first search (DFS) tree. (As an example: the DFS iteration of the
processes in Figure 3.7 is 1, 8415, 8416, 9298, 9204, 2808, 3028, 3610, 4005.)
Linux maintains its process tree as a series of lists. Examining the
task struct in <linux/sched.h>, we see two struct list head objects:
children
and
sibling
These objects are pointers to a list of the task’s children, as well as its siblings.
Linux also maintains a reference to the initial task in the system — init task
— which is of type task struct. Using this information as well as macro
operations on lists, we can iterate over the children of init task as follows:

struct task struct *task;
struct list head *list;

list for each(list, &init task->children) {
task = list entry(list, struct task struct, sibling);
/* task points to the next child in the list */
}
The list for each() macro is passed two parameters, both of type struct
list head:
• A pointer to the head of the list to be traversed
• A pointer to the head node of the list to be traversed
At each iteration of list for each(), the first parameter is set to the list
structure of the next child. We then use this value to obtain each structure in
the list using the list entry() macro.

Assignment

Beginning from init task task, design a kernel module that iterates over all
tasks in the system using a DFS tree. Just as in the first part of this project, output
the name, state, and pid of each task. Perform this iteration in the kernel entry
module so that its output appears in the kernel log buffer.
If you output all tasks in the system, you may see many more tasks than
appear with the ps -ael command. This is because some threads appear as
children but do not show up as ordinary processes. Therefore, to check the
output of the DFS tree, use the command
ps -eLf
This command lists all tasks—including threads—in the system. To verify that
you have indeed performed an appropriate DFS iteration, you will have to
examine the relationships among the various tasks output by the ps command.

SAMPLE ASSIGNMENT
Powered by WordPress