Sending Netlink Taskstats message using libnl-3

前端 未结 1 1992
鱼传尺愫
鱼传尺愫 2021-01-14 16:31

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

相关标签:
1条回答
  • 2021-01-14 17:21

    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.

    0 讨论(0)
提交回复
热议问题