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
8
votes
0 answers

getting notified on flock/lockf/fcntl changes without polling

Is there a way (in Linux) of getting updates on the lockedness status of a file without polling? I know that the status can be polled via a lockf(fd, F_TEST) or speculative LOCK_NB|LOCK_SH, but polling is bad(tm). Of course, finding out when a file…
user2769258
  • 584
  • 3
  • 3
8
votes
4 answers

Prevent running concurrent instances of a python script

Possible Duplicate: Python: single instance of program I need to prevent a cron job from running concurrent instances when a job takes longer to complete than the launcher interval. I'm trying to use the flock concept to achieve this, but fcntl…
tponthieux
  • 1,502
  • 5
  • 18
  • 30
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,536
  • 2
  • 34
  • 55
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,946
  • 3
  • 44
  • 65
7
votes
3 answers

redirecting standard output in c then resetting standard output

I'm trying to use redirects in C to redirect input to one file and then set standard output back to print to the screen. Could someone tell me what's wrong with this code? #include #include #include int main(int argc,…
David
  • 2,080
  • 5
  • 29
  • 44
7
votes
1 answer

How to perform file-locking on Windows without installing a new package

I've added code to a Python package (brian2) that places an exclusive lock on a file to prevent a race condition. However, because this code includes calls to fcntl, it does not work on Windows. Is there a way for me to place exclusive locks on…
abcd
  • 10,215
  • 15
  • 51
  • 85
7
votes
2 answers

How to check if a file is locked or not?

I have the following code where I want to check if the file is locked or not. If not then I want to write to it. I am running this code by running them simultaneously on two terminals but I always get "locked" status every time in both tabs even…
Emperor Penguin
  • 394
  • 2
  • 8
7
votes
1 answer

How to lock and unlock pid file with "fcntl()"

I make a reseach on the net and even on the stackoverflow inorder to find an example of using fcntl() to lock and unlock pid file "/var/run/myapp.pid" but I did not find a clear example for that. Could you point me to an example using fcntl() to…
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
7
votes
3 answers

What is the purpose of calling fcntl() be called with the file descriptor as -1 and cmd as F_GETFL?

I am trying to understand what this line of code means: flags = fcntl(-1,F_GETFL,0);
42_huh
  • 185
  • 1
  • 1
  • 12
6
votes
1 answer

Allocate file on disk without zeroing

I need to allocate huge file without zeroing it's content. I'm producing this steps fopen => ftruncate => fclose => mmap => (...work...) => munmap with huge file sizes (hundreds of gigabytes). App hangs on termination for a few minutes while system…
k06a
  • 17,755
  • 10
  • 70
  • 110
6
votes
1 answer

Python : Locking text file on NFS

I have a file results.txt on a server which is accessed by multiple VMs through NFS. A process runs on each of these VMs which reads the results.txt file and modifies it. If two processes, A and B, read the file at the same time, then modification…
gaganso
  • 2,914
  • 2
  • 26
  • 43
6
votes
2 answers

Why fcntl(fd, F_SETFL, 0) use in serial port programming

I am starting serial port programming in Linux. After reading several examples on the web, I don't understand exact effect of fcntl(fd, F_SETFL, 0)? It is clearing bits, but what flags does it affect? What does it set and or clear?
msc
  • 33,420
  • 29
  • 119
  • 214
6
votes
3 answers

cannot switch to blocking mode using fcntl in linux

I have a sample program: int main() { const char* fn = "/tmp/tmpfifo"; int i = mkfifo(fn, 0666); int fd = open(fn, O_RDONLY | O_NONBLOCK); int flags = fcntl(fd, F_GETFL); flags &= ~O_NONBLOCK; fcntl(fd, F_SETFL, flags); char…
hovnatan
  • 1,331
  • 10
  • 23
6
votes
3 answers

file write lock and child process

If a process give a file a write lock and then it spawn a child process, is lock inherited by the child process? If yes, then there is 2 process have the write lock, I learned that there is only 1 process can have a write lock, some truth? here is a…
Chenglu
  • 1,757
  • 2
  • 14
  • 23
6
votes
2 answers

F_SETPIPE_SZ undeclared

I have included following headers: #include #include #include #include #include #include #include #include I have also tried to use #define…
Marko
  • 1,267
  • 1
  • 16
  • 25
1
2
3
15 16