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.

216 questions
34
votes
3 answers

How to get hard disk serial number using Python

How can I get the serial number of a hard disk drive using Python on Linux? I would like to use a Python module to do that instead of running an external program such as hdparm. Perhaps using the fcntl module?
Forge
  • 5,854
  • 6
  • 41
  • 58
26
votes
7 answers

Python fcntl does not lock as expected

On a Debian-based OS (Ubuntu, Debian Squeeze), I'm using Python (2.7, 3.2) fcntl to lock a file. As I understand from what I read, fnctl.flock locks a file in a way, that an exception will be thrown if another client wants to lock the same file. I…
Wolkenarchitekt
  • 17,351
  • 28
  • 102
  • 166
22
votes
1 answer

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…
Daniel Trebbien
  • 35,770
  • 14
  • 104
  • 182
15
votes
2 answers

Is it possible (and safe) to make an accepting socket non-blocking?

I'm looking for a way to interrupt an accept() call on a blocking socket. Using signals is not an option, as this is meant to be in a library and I don't want to clutter the user signals. Using select() is another option, buf for various reason it's…
Norswap
  • 10,130
  • 10
  • 42
  • 57
12
votes
3 answers

open() doesn't set O_CLOEXEC flag

I try to set O_CLOEXEC flag using open() and have no sucess. Consider the following microtest: #include #include int main() { int fd = open("test.c", O_RDONLY | O_CLOEXEC); int ret = fcntl(fd, F_GETFL); if(ret & O_CLOEXEC)…
Ivan Efremov
  • 148
  • 6
11
votes
2 answers

How to force linkage to older libc `fcntl` instead of `fcntl64`?

It seems GLIBC 2.28 (released August 2018) made a fairly aggressive change to fcntl. The definition was changed in to no longer be an external function, but a #define to fcntl64. The upshot is that if you compile your code on a system…
11
votes
1 answer

python lockf and flock behaviour

I have read enough posts on stackoverflow regarding the difference b/w flock/lockf/fcntl but I am unable to answer the below observation: >>> import fcntl >>> a = open('/tmp/locktest', 'w') >>> b = open('/tmp/locktest', 'w') >>> fcntl.lockf(a,…
Jatin Kumar
  • 2,347
  • 5
  • 33
  • 45
11
votes
3 answers

How do I atomically create a locked file in Linux?

Scenario: I have many processes running that need to fetch files over the net. If the file is already downloaded, I want it cached on disk. If another process is downloading the file, block until it is finished downloading. I've been trying to find…
UsAaR33
  • 3,218
  • 2
  • 26
  • 53
11
votes
1 answer

How can I make a non-blocking request for an exclusive lock using File#flock?

How Should I Request a Non-Blocking Lock? Why doesn't Ruby's File#flock work as expected when separate attempts are made to lock a file? Locking the file in a block is not the correct solution for this issue because the point is to show the behavior…
Todd A. Jacobs
  • 71,673
  • 14
  • 128
  • 179
10
votes
1 answer

How to specify a github repo as the source of dependency of a module in Raku?

My module depends on the Fcntl module (https://github.com/manchicken/perl6-Fcntl), which hasn't been updated in a long time and is broken. However, there's a fork (https://github.com/jonathanstowe/perl6-Fcntl) that works for me if I zef install it…
cowbaymoo
  • 1,162
  • 3
  • 12
9
votes
1 answer

Setting stdout to non-blocking in python

Prior warning: I'm hacking around here out of curiosity. I have no specific reason to do what I'm doing below! Below is done on Python 2.7.13 on MacOS 10.12.5 I was hacking around with python and I thought it'd be interesting to see what happened if…
Andrew Parker
  • 1,265
  • 1
  • 14
  • 23
9
votes
3 answers

How to properly convert a C ioctl call to a python fcntl.ioctl call?

Following an example on resetting a serial port in Linux I wanted to translate the following snippet fd = open(filename, O_WRONLY); ioctl(fd, USBDEVFS_RESET, 0); close(fd); into valid python code. Here is what I have tried so far file_handler =…
Alex
  • 34,021
  • 64
  • 178
  • 371
8
votes
2 answers

c - Usage of F_GETFL and F_SETFL

While trying to use fcntl() with command F_GETFL and F_SETFL, I got some questions: Why the flag returned by fcntl(fd, F_GETFL) only include a subset of bits of what I set when open file? Does it only show the ones that are modifiable? When use…
user218867
  • 16,252
  • 12
  • 112
  • 156
7
votes
1 answer

Deadlock with flock, fork and terminating parent process

I have a pretty complicated python program. Internally it has a logging system that uses an exclusive (LOCK_EX) fcntl.flock to manage global locking. Effectively, whenever a log message is dumped, the global file lock is acquired, message is…
UsAaR33
  • 3,218
  • 2
  • 26
  • 53
7
votes
2 answers

Is there a way to know how much data is available in a Python socket to receive?

I have figured out that I must use ioctl. There are similar questions here: How to tell how much data is in a Socket's send buffer Determing the number of bytes ready to be recv()'d My questions are: What is an equivalent to FIONREAD in Python?…
utapyngo
  • 6,236
  • 2
  • 39
  • 62
1
2 3
14 15