The following code loops over the ancestors of curr_task
, all the way to the swapper
process (i.e the "most distant" ancestor of any Linux process), where it stops because swapper == swapper->parent
.
while (curr_task != curr_task->parent) ...get curr_task info curr_task = curr_task->parent
The problem is I also want to get the swapper
process's info. There are a couple obvious ways to do this (eg goto
statement after the while loop, or a single if
statement after the loop that gets the swapper
info). However, these obvious solutions seems fairly inelegant, and so I'm looking for a more concise solution that doesn't involve the much-maligned goto
or copy/pasting code.