I want to read out linux kernel statistics of a single thread using netlink socket and taskstats.
I could get taskstats to work using a python wrapper (https://githu
The code you provided works fine for me, except for a syntax error in line 26. Make sure you are running the program as root. Note that you are creating a listener for exiting tasks, yet reading a single message, which is, as far as I understand, an ACK. Reading from the socket in a while(1) loop shows parsed messages whenever a task exits on CPU 0.
EDIT: In the case where you are getting stats for a single PID, you should use nla_put_u32 instead:
nla_put_u32(msg, TASKSTATS_CMD_ATTR_PID, 583);
where 583 is an existing process id.