fcntl

linux fcntl - unsetting flag

How do i unset a already set flag using fcntl? For e.g. I can set the socket to nonblocking mode using fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) Now, i want to unset the O_NONBLOCK flag. I tried fcntl(sockfd, F_SETFL, flags | ~O_NONBLOCK). It gave me error EINVAL ...

Where is flock() for Perl on Windows?

I have a Perl script that I'd like to run on Windows, using either Strawberry Perl or ActivePerl; I don't care which. This script however, uses flock() calls, which does not seem to be included in either of those versions of Perl. Can anyone help a Perl n00b get this up and running easily? ...

No manual entry for fcntl problem

When I use `man fcntl' got the message: No manual entry for fcntl which the pkg is needed to install? ps. I use debian. ...

When will fcntl in solaris return a value less then -1 for F_SETLKW

Fromt he Mannul of fcntl in solaris, Upon successful completion, value returned for F_SETLKW will be "Value other than -1". But Apache httpd 1.3.41 source code (http_main.c) check if the returned value is positive like: int ret; while ((ret = fcntl(lock_fd, F_SETLKW, &unlock_it)) < 0 && errno == EINTR) { /* nop */ } if (ret < 0) ...

fcntl issues compiling C++

{net04:~/xxxx/wip} gcc -o write_test write_test.c In file included from write_test.c:4: global.h:10: warning: `b' initialized and declared `extern' This code uses fcntl.h and the file-handling functions defined - like open(), write(), close() etc.. The code compiles and works as intended. {net04:~/xxxx/wip} gcc -o write_test write_t...

fcntl() for thread or process synchronization?

Is it possible to use fcntl() system call on a file to achieve thread/process synchronization (instead of semaphoress)? ...

File r/w locking and unlink

Hello, I have following problem. I want to create a file system based session storage where each session data is stored in simple file named with session ids. I want following API: write(sid,data,timeout), read(sid,data,timeout), remove(sid) where sid==file name, Also I want to have some kind of GC that may remove all timed-out session...

what's the purpose of fcntl with parameter F_DUPFD

I traced an oracle process, and find it first open a file /etc/netconfig as file handle 11, and then duplicate it as 256 by calling fcntl with parameter F_DUPFD, and then close the original file handle 11. Later it read using file handle 256. So what's the point to duplicate the file handle? Why not just work on the original file handle?...

Shared mmap co-ordination using fcntl locks?

When using mmap() for shared memory (from Linux, or other UNIX-like systems) is it possible (and portable) to use fcntl() (or flock() or lockf() functions) to co-ordinate access to the mapping? Responses to this SO question seems to suggest that it should work. The idea I have in mind would be to have the shared memory structured with...

Problems compiliing c++ code using cygwin

I am trying to compile some source code in cygwin (in windows 7) and get the following error when I run the make file g++ -DHAVE_CONFIG_H -I. -I.. -I.. -Wall -Wextra -Werror -g -O2 -MT libcommon_a Fcntl.o -MD -MP -MF .deps/libcommon_a-Fcntl.Tpo -c -o libcommon_a-Fcntl.o `test -f 'Fcntl.cpp' || echo './'`Fcntl.cpp Fcntl.cpp: In functi...

Is O_NONBLOCK being set a property of the file descriptor or underlying file?

From what I have been reading on The Open Group website on fcntl, open, read, and write, I get the impression that whether O_NONBLOCK is set on a file descriptor, and hence whether non-blocking I/O is used with the descriptor, should be a property of that file descriptor rather than the underlying file. Being a property of the file descr...

Utility that helps in file locking - expert tips wanted

I've written a subclass of file that a) provides methods to conveniently lock it (using fcntl, so it only supports unix, which is however OK for me atm) and b) when reading or writing asserts that the file is appropriately locked. Now I'm not an expert at such stuff (I've just read one paper [de] about it) and would appreciate some fee...

Uninterruptible read/write calls

At some point during my C programming adventures on Linux, I encountered flags (possibly ioctl/fcntl?), that make reads and writes on a file descriptor uninterruptible. Unfortunately I cannot recall how to do this, or where I read it. Can anyone shed some light? Update0 To refine my query, I'm after the same blocking and guarantees th...

Can I get fcntl and Perl alarms to cooperate?

I'm on linux, nfs, with multiple machines involved. I'm trying to use fcntl to implement filelocking. I was using flock until I discovered it only works between processes on the same machine. Now when I call fcntl with F_SETLKW, perl alarms (for adding a timeout) don't work as before. This would normally be ok, but ctrl-c doesn't reall...

flock() question

I have a question about how flock() works, particularly in python. I have a module that opens a serial connection (via os.open()). I need to make this thread safe. It's easy enough making it thread safe when working in the same module using threading.Lock(), but if the module gets imported from different places, it breaks. I was thinkin...