Private Writes Vanish

Process A and process B both map the first page of the same file.

/* process A */
int fd = open("data", O_RDWR);
char *p = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
p[0] = 'X';

/* process B */
int fd = open("data", O_RDWR);
char *q = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
q[1] = 'Y';
msync(q, 4096, MS_SYNC);

After both run, what is on disk at offsets 0 and 1?

A

Process A crashes on p[0] = 'X', because close(fd) tore down the mapping

B

Offset 0 unchanged, offset 1 is Y

C

Offset 0 is X, offset 1 is Y

D

Neither write reaches disk until each process calls munmap