c - How to robustly write to a slow & unreliable nsf -


i'm not expert in c , i'm looking advice to make program more robust , reliable. give context: i've written program scientific computation takes quite long time (about 20h) i'm executing on large university hpc linux cluster using slrum scheduling system , nsf mounted file systems. seems happen time during 20h connection file system goes stale (on entire machine; independent of program) , first attempt open & write file takes long time , results in segfault cored dumped error have far not been able precisely track down. below minimal file @ least conceptually reproduces error: program starts, opens file , works. program long computation (simulated sleep()), tries open & write same file again, , fails. conventions make code more robust , reliably write results file without crashing?

#include <stdio.h> #include <stdlib.h> #include <unistd.h>  int main(int argc, char **argv) {     // declare variables     file *outfile;     char outname[150] = "result.csv";      // open file writing     printf("checking if output file '%s' writable?", outname);     outfile=fopen(outname, "w");     if (outfile == null) {         perror("failed: ");         exit(exit_failure);     }     fclose(outfile);     printf(" passed.\n");      // computation takes long (around 19h)     sleep(3);      // open file again , write results     printf("writing results %s ...", outname);     outfile=fopen(outname, "w");     if (outfile == null) {         perror("failed writing in tabulate_vector_new: ");         exit(exit_failure);     }     fprintf( outfile, "this important result.\n");     fclose(outfile);      printf(" done.\n");     return 0; } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -