How to write a simple WatchDog Timer in C on Linux?

The TCP KEEPALIVE timer has a default duration of 2 hours.
What are the best methods for understanding that a TCP connection / socket is not working as soon as possible -

  • Does WatchDog use a better way to do this?

  • How to implement a WatchDog timer for this?
    I browsed quite widely (maybe I use the wrong search parameters), but I did not see such an implementation for Linux GPOS, all I see is a hardware-based, built-in system timer, which is hardware dependent.

Usually what you do after you discover that the socket / connection is dead.

  • Do you close only socket_descriptor?
  • Does socket_descriptor close all kernel resources associated with this connection?
  • How do you free all resources related / distributed in user space? You write a routine to do. If so, how do you track the resources you allocate in user space?
+3
source share
1 answer

It is not possible to detect that the TCP connection is dead "ASAP". If the host, on the other hand, is dead, it is no longer involved in the TCP connection dialog box, and the only way to notice that it is a timeout in the connection.

You can reduce the latency on the socket to “notice” the problem earlier, but this is not a good solution in general.

, "ping" . , "".

, , , .

, , (, ), . ( ), .

, . " " struct, (, fd), .

( " " Linux . /TCP- .)

+4

All Articles