Questions tagged [fcntl]

fcntl refers to a function that provides control over the open file referenced by a file descriptor

fcntl refers to a function that provides control over the open file referenced by a file descriptor.

234 questions
5
votes
1 answer

How to make sense of O_RDONLY = 0?

I am dealing with file status flags. Among test I performed, I found #include #include "fcntl.h" int main() { const int flag = O_RDONLY; printf( "*** Flag O_RDONLY = %5d\n", flag); return 0; } produces this output *** Flag…
5
votes
2 answers

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…
gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
5
votes
1 answer

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…
mmccoo
  • 8,386
  • 5
  • 41
  • 60
5
votes
2 answers

Is a Java FileLock a POSIX advisory (fcntl) lock

I have a C++ program that locks files using POSIX advisory locks. That is, it uses the POSIX fcntl system call for lock operations. I want a Java program to interoperate with that C++ program, so I want my Java program to also use POSIX advisory…
Raedwald
  • 46,613
  • 43
  • 151
  • 237
5
votes
1 answer

Are POSIX file locks reentrant?

I am using POSIX mandatory file locks through fcntl. I'm wondering if those locks are reentrant, ie. can a process acquire a lock it already owns ?
paradigmatic
  • 40,153
  • 18
  • 88
  • 147
4
votes
2 answers

What is the order in which a POSIX system clears the file locks that were not unlocked cleanly?

The POSIX specification for fcntl() states: All locks associated with a file for a given process shall be removed when a file descriptor for that file is closed by that process or the process holding that file descriptor terminates. Is this…
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
4
votes
2 answers

How to get the mode of a file descriptor?

I mean to use fdopen FILE *fdopen(int fd, const char *mode); In man pages, it is stated that "The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor." So I have to first…
4
votes
0 answers

How to create symbolic link to a path that contains unicode characters?

I am using UNIX function symlink() to link a path that contains Unicode characters. However, when I read the link, it is returning ? instead of Unicode characters. This is what my method looks like : if (symlink("symlink.jpg", "/real/path/光芒.jpg")…
blackbeard
  • 385
  • 2
  • 12
4
votes
2 answers

What is the compelling use case for the FD_CLOEXEC flag?

I've just read this: What does the FD_CLOEXEC fcntl() flag do? and I understand what FD_CLOEXEC does, but not why it's important. Why not just close all the relevant file descriptors before exec()ing something? And why is it so critical to set…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
1 answer

Why is File::FcntlLock's l_type always "F_UNLCK" even if the file is locked?

The Perl subroutine below uses File::FcntlLock to check if a file is locked. Why does it return 0 and print /tmp/test.pid is unlocked. even if the file is locked? sub getPidOwningLock { my $filename = shift; my $fs = new File::FcntlLock; …
Saulo Silva
  • 1,219
  • 1
  • 20
  • 37
4
votes
1 answer

Disable DSUSP in Python

An OSX user submitted a bug that CTRL+Y causes a python terminal application to be suspended, via dsusp causing SIGTSTP to be sent when the Python program tried to read on stdin. The code below to solves the problem: (context) import sys import…
Thomas
  • 6,515
  • 1
  • 31
  • 47
4
votes
3 answers

when is the arg for F_GETFL fcntl command required?

int fcntl(int fd, int command, ... /* arg */ ); Is it portable: flags = fcntl(fd, F_GETFL); (note: no arg)? Both Linux and FreeBSD man pages say that arg is ignored: F_GETFL (void) Get the file access mode and the file status flags; arg is…
jfs
  • 399,953
  • 195
  • 994
  • 1,670
4
votes
1 answer

USB Stick Serial number in Python

I am trying to get the serial number (or any unique hardware based identifier) of a USB flash drive using Python on Linux. I started with the recipe I found in this SO question. The code in that link work great for fixed hard drives. For example…
meawoppl
  • 2,714
  • 1
  • 23
  • 30
4
votes
3 answers

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)?
raj_arni
  • 959
  • 2
  • 15
  • 29
4
votes
2 answers

how to use O_ASYNC and fcntl in perl?

i want to use O_ASYNC option and when the pipe can read , the SIGIO's handler will run . but the following code are not work . any one can help me ? #!/bin/env perl use Fcntl; $SIG{IO}= sub { print "catch SIGIO!\n"; }; my…
Chinaxing
  • 8,054
  • 4
  • 28
  • 36
1 2
3
15 16