Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this project, you will write a kernel module that lists all current tasks in a Linux system. ? Part IIterating over Tasks Linearly Design

In this project, you will write a kernel module that lists all current tasks in a Linux system.

? Part IIterating over Tasks Linearly

Design a kernel module that iterates through all tasks in the system using the for_each_process() macro(in ).

In particular, output the process id, task name (known as executable name), and state 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.

image text in transcribed

expected output for part 1 of the work

Part IIIterating 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.?

Examining the task struct in , we see two struct list head objects: children and sibling.

These objects are pointers to a list of the tasks children, as well as its siblings.

Beginning from the init_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 pid, name, and state of each task.

Perform this iteration in the kernel entry module so that its output appears in the kernel l

To check the output of the DFS tree, use the command ps -eLf

expected output for part 2

image text in transcribed

D os@os-VirtualBox: ~/??/HW4/Linear 5749.665199] pid: 1 pname: systemd state: 1 5749.665200] pid: 2| pname: kthreadd | state: 1 5749.665200] pid: 4| pname: kworker/0:0H I state: 1 5749.6652011 pid: 6 I pname: mm percpu wg l state: 1 5749.665202] pid: 7| pname: ksoftirqd/0 state: 1 5749.665203] pid: 8| pname: rcu sched state: 1 5749.665204] pid: 9 I pnane: rcu bh | state: 1 5749.665205] pid: 10 pname: migration/0 I state: 1 5749.665206] pid: 11 pname: watchdog/o state: 1 5749.665207] pid: 12 pnae: cpuhp/0 I state: 1 5749.665208] pid: 13 I pnane: kdevtmpfs | state: 1 5749.665209] pid: 14 pname: netns I state: 1 5749.665209] pid: 15 I pname: khungtaskd | state:1 5749.665210] pid: 16 pname: oom_reaper| state: 1 5749.665211] pid: 17 I pnane: writeback | state: 1 5749.665212] pid: 18 I pnane: kcompactdo state: 1 5749.665213] pid: 19 I pnane: ksmd state: 1 L 5749.665214] pid: 20 I pname: khugepaged | state: 1 5749.665215] pid: 21 pname: crypto | state: 1 5749.665216] pid: 22 I pname: kintegrityd state: 1 5749.665216] pid: 23 I pnane: kblockd | state: 1 5749.665217] pid: 24 pname: ata sff I state: 1 5749.665218] pid: 25 pname: md state: 1 5749.665219] pid: 26 pname: edac-poller I state: 1 5749.665220] pid: 27 pname: devfreq wq | state: 1 5749.665221] pid: 28 pname: watchdogd state:1 5749.665222] pid: 32 I pnane: kauditd | state: 1 5749.665223] pid: 33 I pnane: kswapd0 | state: 1 5749.665224] pid: 34 I pnane: ecryptfs-kthrea | state: 1 5749.665224] pid: 76 I pname: kthrotld | state: 1 5749.6652251 pid: 77 I pname: acpi thermal pm state: 1 5749.665226] pid: 78 | pnane: scsi eh ? I state: 1 5749.665227] pid: 79 | pna e : scsi tnf ? I state: 1 5749.665228] pid: 80 | pnane: scsi eh 1 I state: 1 5749.6652291 pid: 81 I pname: scsi tmf 1 state: 1 5749.665229] pid: 87I pnae: ipv6_addrconf state: 1 L 5749.665230] pid: 112 I pname: charger_manager I state: 1 5749.665231] pid: 163 I pname: kworker/0:1H state: 1 5749.6652321 pid: 164 I pname: scsi eh 2I state: 1 5749.6652331 pid: 165 I pname: scsi tmf 2 | state: 1 5749.665234] pid: 190 I pname: jbd2/sda1-8 I state: 1 5749.665235] pid: 191 I pnae: ext4-rsv-conver | state: 1 5749.665235] pid: 220 I pnane: systend-journal state: 1 5749.665236] pid: 243 I pname: systend-udevd | state: 1 L 5749.665237] pid: 294 pname: iprt-VBoxwQueue | state: 1 5749.665238] pid: 295 I pnane: systend-tinesyn state: 1 5749.665239] pid: 341 I pname: ttm_swap state:1 5749.665239] pid: 632 | pname: ModemManager | state: 1 5749.665240] pid: 634 I pnae avahi-daemon | state: 1 5749.665241] pid: 635 I pnae: dbus-daemon | state: 1 5749.665242] pid: 644 I pnae: avahi-daemon | state: 1 5749.665243] pid: 650 I pname: NetworkManager | state: 1 5749.6652441 pid: 669 I pname: snap d state: 1 D os@os-VirtualBox: ~/??/HW4/Linear 5749.665199] pid: 1 pname: systemd state: 1 5749.665200] pid: 2| pname: kthreadd | state: 1 5749.665200] pid: 4| pname: kworker/0:0H I state: 1 5749.6652011 pid: 6 I pname: mm percpu wg l state: 1 5749.665202] pid: 7| pname: ksoftirqd/0 state: 1 5749.665203] pid: 8| pname: rcu sched state: 1 5749.665204] pid: 9 I pnane: rcu bh | state: 1 5749.665205] pid: 10 pname: migration/0 I state: 1 5749.665206] pid: 11 pname: watchdog/o state: 1 5749.665207] pid: 12 pnae: cpuhp/0 I state: 1 5749.665208] pid: 13 I pnane: kdevtmpfs | state: 1 5749.665209] pid: 14 pname: netns I state: 1 5749.665209] pid: 15 I pname: khungtaskd | state:1 5749.665210] pid: 16 pname: oom_reaper| state: 1 5749.665211] pid: 17 I pnane: writeback | state: 1 5749.665212] pid: 18 I pnane: kcompactdo state: 1 5749.665213] pid: 19 I pnane: ksmd state: 1 L 5749.665214] pid: 20 I pname: khugepaged | state: 1 5749.665215] pid: 21 pname: crypto | state: 1 5749.665216] pid: 22 I pname: kintegrityd state: 1 5749.665216] pid: 23 I pnane: kblockd | state: 1 5749.665217] pid: 24 pname: ata sff I state: 1 5749.665218] pid: 25 pname: md state: 1 5749.665219] pid: 26 pname: edac-poller I state: 1 5749.665220] pid: 27 pname: devfreq wq | state: 1 5749.665221] pid: 28 pname: watchdogd state:1 5749.665222] pid: 32 I pnane: kauditd | state: 1 5749.665223] pid: 33 I pnane: kswapd0 | state: 1 5749.665224] pid: 34 I pnane: ecryptfs-kthrea | state: 1 5749.665224] pid: 76 I pname: kthrotld | state: 1 5749.6652251 pid: 77 I pname: acpi thermal pm state: 1 5749.665226] pid: 78 | pnane: scsi eh ? I state: 1 5749.665227] pid: 79 | pna e : scsi tnf ? I state: 1 5749.665228] pid: 80 | pnane: scsi eh 1 I state: 1 5749.6652291 pid: 81 I pname: scsi tmf 1 state: 1 5749.665229] pid: 87I pnae: ipv6_addrconf state: 1 L 5749.665230] pid: 112 I pname: charger_manager I state: 1 5749.665231] pid: 163 I pname: kworker/0:1H state: 1 5749.6652321 pid: 164 I pname: scsi eh 2I state: 1 5749.6652331 pid: 165 I pname: scsi tmf 2 | state: 1 5749.665234] pid: 190 I pname: jbd2/sda1-8 I state: 1 5749.665235] pid: 191 I pnae: ext4-rsv-conver | state: 1 5749.665235] pid: 220 I pnane: systend-journal state: 1 5749.665236] pid: 243 I pname: systend-udevd | state: 1 L 5749.665237] pid: 294 pname: iprt-VBoxwQueue | state: 1 5749.665238] pid: 295 I pnane: systend-tinesyn state: 1 5749.665239] pid: 341 I pname: ttm_swap state:1 5749.665239] pid: 632 | pname: ModemManager | state: 1 5749.665240] pid: 634 I pnae avahi-daemon | state: 1 5749.665241] pid: 635 I pnae: dbus-daemon | state: 1 5749.665242] pid: 644 I pnae: avahi-daemon | state: 1 5749.665243] pid: 650 I pname: NetworkManager | state: 1 5749.6652441 pid: 669 I pname: snap d state: 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

Conduct a needs assessment. page 269

Answered: 1 week ago