#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <err.h>

int main()
{
    int fd;

    while (1) {
        fd = open("file.t.lock", O_WRONLY|O_CREAT|O_EXCL, 0666);
        if (fd != -1) {
            close(fd);
            break;
        }
        if (errno != EEXIST)
            err(1, "some other error");
        sleep(1);
    }
    printf("opened file file.t\n");
    sleep(10);
    printf("closed file file.t\n");
    unlink("file.t.lock");
}
