+static struct timespec global_sleep_value= { .tv_sec= 0, .tv_nsec= 50000 };
+
+static void global_sleep(void)
+{
+#ifdef WIN32
+ sleep(1);
+#else
+ nanosleep(&global_sleep_value, NULL);
+#endif
+}
+
+static void kill_file(const char *file_buffer)
+{
+ FILE *fp= fopen(file_buffer, "r");
+
+ while ((fp= fopen(file_buffer, "r")))
+ {
+ char pid_buffer[1024];
+
+ if (fgets(pid_buffer, sizeof(pid_buffer), fp) != NULL)
+ {
+ pid_t pid= (pid_t)atoi(pid_buffer);
+ if (pid != 0)
+ {
+ if (kill(pid, SIGTERM) == -1)
+ {
+ remove(file_buffer); // If this happens we may be dealing with a dead server that left its pid file.
+ }
+ else
+ {
+ uint32_t counter= 3;
+ while ((kill(pid, 0) == 0) && --counter)
+ {
+ global_sleep();
+ }
+ }
+ }
+ }
+
+ global_sleep();
+
+ fclose(fp);
+ }
+}
+