#include #include #include #include using namespace std; using namespace boost::interprocess; int main(int argc, char *argv[]) { file_lock flock("lock"); if (flock.try_lock()) cout << "Acquired lock" << endl; else { cout << "Could not acquire lock" << endl; return 1; } ifstream file("lock"); // If you comment out the next line the lock stays active during the sleep. file.close(); // also closes lock sleep(30); return 0; }