Ubuntu Pastebin

Paste from laney at Wed, 6 Sep 2017 08:35:19 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include <unistd.h>

int main()
{
        int pid_file = open ("/run/user/1000/seb128.pid", O_CREAT | O_RDWR, 0666);
        int rc = flock (pid_file, LOCK_EX | LOCK_NB);
        if (rc) {
                if (errno == EWOULDBLOCK) {
                        printf ("Not the first instance.\n");
                        return EXIT_FAILURE;
                }
        } else {
                printf ("Yay, it's just me!\n");
                sleep (20);
        }
}
Download as text