LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2013, 02:50 AM   #1
krool89
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
fcntl


#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
char* file = argv[1];
int fd;
struct flock lock;

lock.l_type = F_WRLCK;
lock.l_start = 0;
lock.l_whence = SEEK_SET;
lock.l_len = 50;

printf("Please insert your file : ");
scanf("%s", file);

fd = open (file, O_WRONLY);
printf ("locking\n");

memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;

pause();
return 0;
}


can anyone help me..??
i can compile the program but cant lock file...
WHY...??
 
Old 04-28-2013, 03:53 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Because you didn't read the manual, so you don't know what locking actually means. It doesn't change anything on the file, nor does it prevent opening/closing/reading/writing/deleting/renaming it. The only thing locking prevents is locking.

https://en.wikipedia.org/wiki/File_l...x-like_systems

Last edited by NevemTeve; 04-28-2013 at 03:55 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File lock using fcntl aruns06@gmail.com Programming 4 07-13-2012 04:02 AM
Trouble modifying fcntl.h sim0ne Programming 9 12-05-2009 01:13 PM
fcntl F_SETLKW on NFS kpj104 Linux - Kernel 0 05-12-2009 12:49 PM
fcntl I can not understand use level3 Programming 5 06-15-2006 03:15 AM
is a socket already opened? fcntl(); Thinking Programming 1 09-19-2005 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration