Now let's see the (relevant) code of our thrd_showall kernel module:
// ch6/foreach/thrd_showall/thrd_showall.c */
[...]
#include <linux/sched.h> /* current */
#include <linux/version.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 10, 0)
#include <linux/sched/signal.h>
#endif
[...]
static int showthrds(void)
{
struct task_struct *g, *t; // 'g' : process ptr; 't': thread ptr
[...]
#if 0
/* the tasklist_lock reader-writer spinlock for the task list 'should'
* be used here, but, it's not exported, hence unavailable to our
* kernel module */
read_lock(&tasklist_lock);
#endif
disp_idle_thread();
A few points to note regarding the preceding code:
- We use the LINUX_VERSION_CODE() macro to conditionally include a header, as required.
- Please ignore the locking work for now – usage (or the lack thereof) of the tasklist_lock() ...