Question: As illustrated in Section 3.1, the PCB in Linux is represented by the structure the for each process macro easily allows iteration over all current
As illustrated in Section 3.1, the PCB in Linux is represented by the structure the for each process macro easily allows iteration over all current tasks task struct, which is found in the include file. In Linux 160 Chapter 3 Part I --Iterating over Tasks Linearly in the system: #include struct task struct *task; for each process (task) { /* on each iteration task points to the next task */ } The various fields in task.struct can then be displayed as the program loop through the for each process() macro. Part I Assignment Design a kernel module that iterates through all tasks in the system using the for each process() macro. In particular, output the task name (known as executable name), state, and process id of each task. (You will probably have to read through the task struct structure in 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 As illustrated in Section 3.1, the PCB in Linux is represented by the structure the for each process macro easily allows iteration over all current tasks task struct, which is found in the include file. In Linux 160 Chapter 3 Part I --Iterating over Tasks Linearly in the system: #include struct task struct *task; for each process (task) { /* on each iteration task points to the next task */ } The various fields in task.struct can then be displayed as the program loop through the for each process() macro. Part I Assignment Design a kernel module that iterates through all tasks in the system using the for each process() macro. In particular, output the task name (known as executable name), state, and process id of each task. (You will probably have to read through the task struct structure in 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