Wednesday, 15 June 2011

Linux ANSI C simultaneous access to files and locking -



Linux ANSI C simultaneous access to files and locking -

i writing linux ansi c cgi-bin server programme simultaneous access files.

is possible distinguish between file existence , file locking? can't find reply google. i'd write programme tries open file few seconds if fd<0 (thinking file locked while). if file not exist it's fd <0. programme waste time waiting.

suppose few threads seek append same file no locking. 1 tries add together "aaaa", - "bbbb". can result file "aabbaabb"? or aaaabbbb or bbbbaaaa? or result unpredictable?

am assuming ieee std 1003.1-2001 might defer iso c standard...

in case fopen fails i.e. fd < 0 scheme sets error codes... can check error codes. in case of file non-existent, returned error be

enoent component of filename not name existing file or filename empty string.

for more reference visit: http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

for point 2: have been doing logging of info in scheme more 100 processes writing single file simultaneously have never seen merger of records(file opened in append mode). i.e. aaaabbbb

c linux file locking

No comments:

Post a Comment