In the preceding code, we made use of a few of the kernel's built-in helper methods to extract various members of the task structure. This is the recommended approach; for example, we use task_pid_nr() to peek at the PID member instead of directly via current->pid. Similarly, the process credentials within the task structure (such as the EUID members we showed in the preceding code) are abstracted within struct cred and access to them is provided via helper routines, just like with from_kuid(), which we used in the preceding code. In a similar fashion, there are several other helper methods; look them up in include/linux/sched.h just below the struct task_struct definition.
Why is this the case? Why not simply access task structure members directly via current-><member-name>? Well, there are various real reasons; one, perhaps the access requires a lock to be taken (we cover details on the key topic...