title: How can I monitor the NIC status(up/down) in a C program without polling the kernel?
body: <p>Now I need to get the status of the NIC(up or down) in the real time. That means I have to catch the kernel interrupt when the NIC up or down in a blocked loop. </p>
  
  <p>The first stupid method from mine is that check on the <strong><em>/sys/class/net/eth0/operstate</em></strong> or use <strong><em>ioctl</em></strong> to get the ifflag every 100ms in a loop. But 100ms is too long for the app to reroute the traffic and also polling kernel every 100ms is not good idea.</p>
  
  <p>Once I notice the <strong><em>inotify</em></strong> function that can monitor the files in a block mode. But unfortunately, it can't monitor the /sys/class/net/eth0/operstate file since /sys is located in the RAM not in the disk.</p>
  
  <p>So, is there any methods except writing a kernel module to catch the NIC interrupt(up/down) in the C program with a block mode? </p>