Two Writers One Offset
Two independent processes append audit lines to the same file. Each runs this, once per line:
int fd = open("audit.log", O_WRONLY | O_CREAT, 0644);
off_t end = lseek(fd, 0, SEEK_END);
pwrite(fd, line, len, end);
close(fd);
Under load the log ends up with fewer lines than were written, and some lines are half-overwritten by others. What is the defect and the fix?
Sign in to answer questions and track your progress
Sign In