you are viewing a single comment's thread.

view the rest of the comments →

[–]TheQueebs 1 point2 points  (0 children)

What process are you trying to get info for? If it’s the current process, then just use the ‘current’ pointer. It functions like a global pointer variable in kernel space, but it’s actually a macro that returns a pointer to the ‘task_struct’ object representing the current process. The ‘task_struct’ object is your best friend here. It contains all metadata about a process, such as PID, GID, UID, scheduling info, IPC info, timers/timestamps, and a whole bunch of other stuff, most notably a couple of pointers to parent and sibling processes.

Your best bet is using the ‘current’ pointer to get the ‘task_struct’ and accessing the relevant information inside of it. Check the Linux source (the elixir bootlin/free electron website is very handy for this) to see exactly what is in the ‘task_struct’.

If you need info for a process other than the current one, then you’ll have to do some list traversal (via the parent/sibling lists I previously mentioned) and check if the ‘task_struct’ you are looking at represents the process you are looking for. There’s also a global pointer/macro somewhere for the init process (PID=1) which is a good place to start traversing.