A multi-cpu server is running several processes. One process has a thread that should always be in a spinning state, using 100% of the CPU it's been assigned. My current method (besides asking the developer...) is using strace
on the process which waits for information to arrive at it's open file descriptor and checks it continuously using recvfrom(2)
where erno
is set to EAGAIN
and method is returning -1 when no packets are to be read from network socket.
I'm not comfortable stack tracing production set-ups, and it's a unwieldy way of determining this information at best. I was poking about proc(5)
and thought that the value of the flags field in /proc/[pid]/fdinfo
might be useful to check if that process was using a socket that called open(2)
with the O_NONBLOCK
mode.
I'm struggling to reverse engineer this value at the moment. I know it represents the bitwise OR of the file status and file mode. So I think I can check the source headers for the value of constants open(2)
uses on that particular kernel and then bitwise OR them until I find a value that matched what's in fdinfo
. That seems rather clunky, if anybody can validate the above method (I can't yet) or provide a more elegant solution I'd be much obliged.
I also know fnctl(2)
can set a file descriptor to a non-blocking state, but am treating that equivalent to open for the moment