Skip to content

Race · 7 min

The file was there when you asked

The assumption

If access says the file is there, the open that follows will find it.

#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void) {
  pid_t pid = fork();
  if (pid == 0) {
    unlink("/work/data");
    _exit(0);
  }

  int there = access("/work/data", R_OK);
  int fd = open("/work/data", O_RDONLY);
  printf("%d %d\n", there, fd);

  int status;
  waitpid(pid, &status, 0);
  return 0;
}

Not explored

Read the assumption first. Then find out whether the scheduler agrees with it.

Everything you do here stays in this browser.Part of liter8.sh