source: testjes/testdirlock.cpp

Last change on this file was 10, checked in by willem, 11 years ago

willem

File size: 624 bytes
Line 
1#include <iostream>
2#include <unistd.h>
3#include <fcntl.h>
4#include <stdio.h>
5
6int main()
7{
8  int f;
9  f = open(".",O_RDWR);
10  if (f < 0)
11  {
12    perror("open error:");
13    return 1;
14  }
15  int rc;
16  struct flock lock;
17  lock.l_type = F_RDLCK|F_WRLCK;
18  lock.l_whence = SEEK_SET;
19  lock.l_start  = 0;
20  lock.l_len    = 0;
21
22  std::cout << "getting lock ... \n";
23  rc = fcntl(f,F_SETLKW,&lock);
24
25  std::cout << " got it, sleeping\n";
26  sleep(5);
27  lock.l_type = F_UNLCK;
28  lock.l_whence = SEEK_SET;
29  lock.l_start  = 0;
30  lock.l_len    = 0;
31  rc  = fcntl(f,F_SETLKW,&lock);
32
33  sleep(5);
34  std::cout << "done\n";
35
36  return 0;
37}
Note: See TracBrowser for help on using the repository browser.