lockFile.c 375 Bytes
Newer Older
1 2
#include <stdio.h>

Zach's avatar
Zach committed
3 4 5 6
/*if run serially, works fine.
  If run in parallel, someone will attempt to delete
  a locked file, which will fail */
int main(void)
7 8 9 10 11 12
{
  FILE* file;
  int i;
  const char* fname = "lockedFile.txt";
  file = fopen(fname, "w");

13
  for (i = 0; i < 10000; i++) {
14 15
    fprintf(file, "%s", "x");
    fflush(file);
16
  }
17 18 19
  fclose(file);
  return remove(fname);
}