Questions tagged [fcntl]
fcntl refers to a function that provides control over the open file referenced by a file descriptor
224
questions
-1
votes
0
answers
39
views
My function breaks the built-in input() function in some way
I have a function, and it breaks the built-in input() function in some way.
getKeyCode() returns the keycode of the key being pressed. It functions well, both for blocking=True and blocking=False.
def ...
0
votes
1
answer
63
views
Perl Fcntl calls to F_SETPIPE_SZ or F_GETPIPE_SZ throws "Bad file descriptor"
Background:
I am trying to write a small script that logs JSONS concurrently, if the file sizes are small, things are ok. But when file sizes are large, processes start to overwrite each other. This ...
0
votes
1
answer
64
views
How can I unlock file in c
I tried to lock-unlock file in c. If the file is exist then there is no problem but if file does not exist and file is created, file stays locked. If I tried to open the file, It did not open. It says ...
0
votes
0
answers
27
views
Fcntl locking in Python
I'm trying to understand why fcntl docs and most examples on the internet don’t use with open()?
Most of the examples go like that:
f = open(file, ‘w’)
fcntl.lockf(f.fileno(), LOCK)
….
f.close()
...
1
vote
1
answer
55
views
How is a read system call different from the istream::read function?
My Operating Systems professor was talking today about how a read system call is unbuffered while a istream::read function has a buffer. This left me a bit confused as you still make a buffer for the ...
2
votes
1
answer
41
views
How can I set a pipe to O_NONBLOCK perl
This works fine:
#!/usr/bin/perl -w
#
#pipe2 - use pipe and fork so child can send to parent
use IO::Handle;
pipe(READER, WRITER);
WRITER->autoflush(1);
if ($pid = fork) {
close WRITER;
...
0
votes
3
answers
97
views
Is it required to use O_TRUNC and O_APPEND together?
I was going through the book The Linux Programming Interface. On page no. 73 Chapter no.4
it is written
fd = open("w.log", O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, S_IRUSR | S_IWUSR);
I read ...
0
votes
0
answers
60
views
Having some troubles with file locks under Linux
My English is poor so you may get confused from my description below.
In Linux, multiple processes were requesting a file lock (flock or fcntl lock), then the previous exclusive file lock was released....
-1
votes
1
answer
47
views
read() not working as expected. Returns value 1 on successful read of large block [duplicate]
I am developing a process that, among other things, will copy files. I've run across a problem that the read function does not work as I expected.
My research and my prior experience tell me that the (...
0
votes
0
answers
47
views
unable to run fcntl on socket on embedded platform
I am working on an embedded platform and I'm having problems with some (seemingly) basic socket operations.
I want to open a socket and set it O_NONBLOCK. I came up with the following sample code:
#...
0
votes
0
answers
14
views
getting notified when lockf exclusive lock is being requested
I have few apps running sharing a file.
Most of my apps are only requesting a simple lock, but one of them is requesting a exclusive lock.
the lock is currently taken that way:
import fcntl
...
0
votes
1
answer
115
views
fcntl doesn't lock/unlock the files [Unix - C]
I'm trying to use fcntl lib (at UNIX c programming) to lock or unlock files but seems isn't lock and I don't know why. I don't receive any error, it looks like that the program doing the lock but ...
0
votes
0
answers
49
views
linux fork() fcntl() for use
I am studying multi-process fcntl().
Child processes share file descriptors.
I want to make only one of the child processes accessible to the file and the others inaccessible.
First, create three ...
0
votes
1
answer
214
views
fcntl not working (doesn't lock the file) in multi-threaded programme
fcntl using code
Hi. I'm trying to access a file with multiple threads,
trying to get synchronization with record lock(fcntl).
The problem is, fcntl doesn't lock the file.
result
I've tried:
each ...
-1
votes
1
answer
420
views
How can I open directory with open() function in C?
I want to open a directory without using <dirent.h>.
I tried this:
#include <fcntl.h>
int fd = open("dir", O_RDONLY, 0);
But it returns fd = -1. Why? As I know, the directory ...
1
vote
0
answers
721
views
Linux File Locking with fcntl and C++
I did two months search on the web for a proper file locking mechanism to be used in a C++ program.
I found a lot on "C and fnctl" which I could proof to work. But all really proper working ...
1
vote
0
answers
36
views
Python fcntl struct contents
Python fcntl module has a function fcntl that accepts a struct as and arg argument. That struct is undocumented, and seems to be platform dependent. Here is a snipped from https://github.com/python/...
0
votes
1
answer
41
views
Why fcntl start=0, len=0, whence=2 works?
According to the fcntl manual, fcntl locking with start=0, len=0, whence=2 should lock the byte range starting from the end of file (whence=2), with offset 0 (start=0) until the end of file (len=0), ...
-4
votes
1
answer
41
views
segmentation err in switch case [closed]
I wrote a code to implement file locking in c. After resolving a errors and ignoring all the warnings haha, I was able to compile the code but now the thing is, When I try to add content to the file, ...
0
votes
1
answer
69
views
The file locking program is NOT LOCKING FILES
I have made a program to have advisory file locking in the c program and below is the code I have written for the task.
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#...
0
votes
0
answers
129
views
having trouble running fcntl and flock in windows Code::Blocks
I have been trying to make a file locking program in windows using Code::Blocks. With to many errors popping in my original code, I decided to copy it from a youtube tutorial video on fcntl. Even ...
3
votes
2
answers
99
views
Why is the c function `open` ~4x slower on MacOS vs. an Ubuntu VM on the same machine?
Why is MacOS ~4x slower to open files than an Ubuntu VM on the same machine here?
A MWE using similar settings to the code this behavior was discovered on
#include <stdio.h>
#include <fcntl.h&...
1
vote
1
answer
448
views
No such file or directory Error when trying to install fcntl using pip?
I'm trying to install fcntl with pip and I entered this into cmd:
pip install pycopy-fcntl
However, this error pops up and I have no idea what it is or how to fix it:
Collecting pycopy-fcntl
Using ...
1
vote
1
answer
397
views
How to get unbuffered output from popen & fgets
I'm using popen to execute a command and read the output. I'm setting the file descriptor to non-blocking mode so that I can put in my own timeout, as follows:
auto stream = popen(cmd.c_str(), &...
0
votes
1
answer
66
views
solaris: O_NDELAY set on stdin: when process exits the shell exits
TLDR: In Solaris, if O_NDELAY is set on stdin by a child process, bash exits. Why?
The following code causes interactive bash (v4.3.33) or tcsh (6.19.00) shells to exit after the process finishes ...
0
votes
1
answer
171
views
how to lock a file so that other process cannot cat it?
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
struct flock fl;
fl.l_start = 0;
fl.l_len = 517; //found the size of the ...
10
votes
1
answer
124
views
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/...
-3
votes
1
answer
20
views
Whether fcntl record lock can work in multithreads
I tried fcntl record lock work in multithreads on linux.
But it seems fcntl record lock doesn't work?
Can fcntl record lock work in multithreads?
3
votes
1
answer
146
views
How to write EOF markers on Magnetic Tape - Python
I have searched a great deal on the web and I am unable to find a way to write an EOF marker on a magnetic tape in Python.
I have the below code (using Python via fcntl.ioctl) which writes records but ...
0
votes
1
answer
91
views
How to perform conditional IO in the file system?
I'm trying to implement a multi-user key-value store over the file system, such as the local Linux or Windows file system, or a network-based one (SMB or NFS). My intent is to fully avoid the need of ...
0
votes
2
answers
312
views
How to get flags of opened fd in C?
I want to get flags of fd was opened before in C.
But I use fcntl(fd,F_GETFD,0) reference by fcntl man page, it always return 1 to me.
#include <stdio.h>
#include <stdlib.h>
#include <...
0
votes
2
answers
284
views
linux read() function from unistd.h doesn't work for me :(
I tried everything i could think of but for some reason it doesn't store the data from the file to "data", but the file has the written data.
#include <fcntl.h>
#include <unistd.h&...
0
votes
1
answer
186
views
Wal-e: unable to to push backups - permission error
We get the following error when we try to push backup using wal-e:
2020-07-16T21:18:55Z <Greenlet at 0x7f2a59fadc48: <wal_e.worker.upload.PartitionUploader object at 0x7f2a59f96cc0>([...
0
votes
1
answer
188
views
Make std::cout do not fail with O_NONBLOCK or make stdin O_NONBLOCK keeping stdout blocking?
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
int main(){
// Make stdin non-blocking
fcntl(STDIN_FILENO, F_SETFL, fcntl(...
4
votes
1
answer
801
views
How to make sense of O_RDONLY = 0?
I am dealing with file status flags.
Among test I performed, I found
#include <stdio.h>
#include "fcntl.h"
int main() {
const int flag = O_RDONLY;
printf( "*** Flag O_RDONLY = %5d\n", ...
2
votes
2
answers
1k
views
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 ...
0
votes
1
answer
464
views
Correct way of using fdopen
I mean to associate a file descriptor with a file pointer and use that for writing.
I put together program io.cc below:
int main() {
ssize_t nbytes;
const int fd = 3;
char c[100] = "...
0
votes
1
answer
210
views
Error message while compiling flock struct C++
I'm trying to use the fcntl() system call to create locks on a file, but in order to do that you need to pass in an instance of the flock struct, which is a structure that is defined in the fcntl.h ...
0
votes
1
answer
294
views
programm can not find constant in libary fcntl.h in c
I am learning C and somehow my programm can not find a constant defined in a libary. In my understanding S_IRUSR|S_IWUSR shoud be defined in fcntl.h, but I get while trying to compile this error:
... ...
0
votes
0
answers
47
views
python file shared across several processes
I have a python process that runs continuously and read every 1 minute a cfg file from disk.
run.py
while True:
parser = configparser.ConfigParser()
parser.read('config.ini')
time.sleep(60)
The ...
0
votes
1
answer
298
views
python lockf: LOCK_EX works but LOCK_SH doesn't
I'm puzzled by the behaviour of the lockf function from the python fcntl library: I can't get a shared lock, while the exclusive one works:
In [1]: import fcntl ...
0
votes
1
answer
71
views
Why does this program give different outputs on ubuntu windows desktop app and on ubuntu virtual box?
The program is basically checking for how fcntl function works. The main program(Pm.c) creates a pipe and 3 child processes by forking. It then does necessary fcntl function on the pipe and then ...
1
vote
1
answer
506
views
Why fcntl() is not blocking on F_SETLKW in WSL?
I was trying to figure out different types of ways to lock a file in linux and i just came across fcntl().
According to man page, fcntl() with F_SETLKW should block if a conflicting lock is held on ...
2
votes
1
answer
1k
views
Docker and fcntl OSError Errno 22 Invalid argument
I've encountered a weird problem and I do not know how to proceed.
I have docker 18.09.2, build 6247962 on a VMware ESXi 6.5 virtual machine running Ubuntu 18.04. I have docker 19.03.3, build ...
11
votes
2
answers
3k
views
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 <fcntl.h> to no longer be an external function, but a #define to fcntl64.
The ...
1
vote
1
answer
85
views
Does Linux / GCC have file sharing allow-deny type support?
Back in DOS, Borland C/C++ you had O_DENYxxx flags available on open(). On MS Visual Studio / Windows you have sopen(), some flavors of open() have O_SHARE_xxxx flags available (ibm docs for example)....
0
votes
0
answers
496
views
Prevent multiple python scripts from accessing a single file simultaneously
I am trying to create a series of images (where each is a composite of 12 smaller images). The blank composite images and the smaller component images already exist. I've written a python script which ...
0
votes
1
answer
218
views
how to notify another process when file lock is released?
I have a small application consisting of two process.
Process A downloads a file. Process B uses the downloaded file.
When Process A downloads a file, it acquires file lock on it. Process B keep ...
2
votes
1
answer
416
views
Implementing lseek in xv6
First off I need to say it's completely possible I'm missing something.
My assignment is to essentially implement 'fprintf'. Now while appending to the file isn't required, I like to go above and ...