Created
June 11, 2024 22:49
-
-
Save jeansymolanza/221db1221da6edbfd867a76188bb563a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... (previous code remains the same) | |
void* check_stop_file(void* arg) { | |
while (!stop_requested) { | |
if (access(STOP_FILE, F_OK) != -1) { | |
// Stop file exists, set the stop flag | |
stop_requested = 1; | |
break; | |
} | |
// Sleep for a short interval before checking again | |
usleep(100000); // Sleep for 100ms | |
} | |
return NULL; | |
} | |
int main(int argc, char **argv) { | |
// ... (previous code remains the same) | |
// Create a thread to check for the STOP file | |
pthread_t stop_thread; | |
pthread_create(&stop_thread, NULL, check_stop_file, NULL); | |
// Main loop to process messages from the pipe | |
while (!stop_requested) { | |
// ... (main loop code remains the same) | |
} | |
// Wait for the stop thread to finish | |
pthread_join(stop_thread, NULL); | |
// ... (remaining code remains the same) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment