#include #include #include #include #include #include #define FILENAME "testfile" int main() { int fd = open( FILENAME, O_RDWR ); if( fd==0 ) { fputs( "Failed to open `" FILENAME "'.", stderr ); return 1; } printf( "flock() returned %d. Now calling close() ...\n", flock( fd, LOCK_EX|LOCK_NB ) ); close( fd ); return 0; }