#include #include #include #include #include int main(int argc, char **argv) { int flags; int mode; int fd, laterfd; int count; struct flock aflock; char aBuffer[1024]; mode = S_IRUSR | S_IRGRP | S_IROTH; mode |= S_IWUSR | S_IWGRP | S_IWOTH; flags = O_RDWR; aflock.l_type = 0; aflock.l_whence = SEEK_SET; aflock.l_start = 0; aflock.l_len = 0; aflock.l_type = F_WRLCK; fd = open( argv[1], flags, mode ); if (!strcmp(argv[2], "lock")) fcntl( fd, F_SETLK, &aflock ); mode = S_IRUSR | S_IRGRP | S_IROTH; flags = O_RDONLY; laterfd = open( argv[1], flags, mode ); count = read(laterfd, aBuffer, 1024); if (count == -1) perror("problem"); printf("count is %d\n", count); return 0; }