As a first example, let's travel back to one of our kernel modules from the companion guide Linux Kernel Programming - Chapter 6, Kernel Internals Essentials – Processes and Threads, in the Iterating over the task list section, here: https://github.com/PacktPublishing/Linux-Kernel-Programming/blob/master/ch6/foreach/thrd_showall/thrd_showall.c. Here, we looped over each thread, printing some details from within its task structure; with regard to this, here's a code snippet where we obtain the name of the thread (recall that it's in a member of the task structure called comm):
// ch6/foreach/thrd_showall/thrd_showall.c
static int showthrds(void)
{
struct task_struct *g = NULL, *t = NULL; /* 'g' : process ptr; 't': thread ptr */
[ ... ]
do_each_thread(g, t) { /* 'g' : process ptr; 't': thread ptr */
task_lock...