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
0
votes
1 answer

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 checking whether the file being downloaded is locked…
Subbu
  • 2,063
  • 4
  • 29
  • 42
0
votes
1 answer

How to tell if the current process has already locked a file?

I'm writing unit tests for a function that may lock a file (using fcntl(fd, F_SETLK, ...)) under some conditions. I want my unit test to be able to EXPECT that the file is or is not locked at certain points. But I can't find any way to test that.…
Ian Barkley-Yeung
  • 141
  • 2
  • 2
  • 7
0
votes
0 answers

How to get the mode a file was opened in C (LINUX)

I want to implement a function that gets as parameter a FILE*, that is already open in write mode (a, a+, w, w+ etc), and reads the contents of that file. The problem here is that the file is already locked (because of the fopen) and I need to close…
0
votes
1 answer

read() returns Bad file descriptor on a valid file descriptor

In the following program, int main() { int fd; char buf[8]={}; remove("file.txt"); fd = creat("file.txt",0666); write(fd,"asdf",5); perror("write"); lseek(fd,0,SEEK_SET); perror("lseek"); read(fd,buf,5); …
0
votes
0 answers

replacement for fcntl function be used for porting project from linux to window

I am doing porting a project from Linux to Windows. This is the code. CIOChannelFileGlib::CIOChannelFileGlib(int fd, std::shared_ptr src, std::shared_ptr sink){ int Flags = fcntl(fd, F_GETFL, 0); DChannel =…
Sera
  • 1
  • 1
0
votes
2 answers

C - moving back the pointer in the file using lseek

I am writing an academic project in C and I can use only and libraries to file operations. I have the function to read file line by line. The algorithm is: Set pointer at the beginning of the file and get current position. Read…
user
  • 4,410
  • 16
  • 57
  • 83
0
votes
1 answer

Polyspace Run-time check alert with C open() function

First, please consider the following piece of code (static function called once from main()): #define SYSFS_GPIO_DIR "/sys/class/gpio" #define MAX_BUF ((UI_8)64) typedef uint8_t UI_8 typedef…
0
votes
2 answers

Programmatically prevent a file to be renamed or deleted but still make it writable

I have one application (let's say App A) that I have no control over and I cannot modify, writes to a file and has the ability to rename and delete it. I have another application (let's say App B) which is reading from the file written by App A. I…
BlueChips23
  • 1,861
  • 5
  • 34
  • 53
0
votes
2 answers

fcntl how to know which process hold lock file?

I'm new with fcntl locking and following this example to create a sample lock in linux using c code: http://www.informit.com/articles/article.aspx?p=23618&seqNum=4 I wonder how can we can print out which process hold the lock file and which process…
RLe
  • 456
  • 12
  • 28
0
votes
1 answer

fcntl() with exec in Solaris

I use fcntl() for file capture and then I call execlp() to open file by nano. I run the program here and in another session. Process from new session also open the file by nano, but it should be waiting for unlock. Effect is same for mandatory and…
Qwerty
  • 3
  • 1
0
votes
0 answers

file locking not working as expected in C

I have a file which will be read and write by the multiple process. So to synchronize the file between multiple processes I was using fcntl(). Let's assume we have a file orignal.txt and we have some content in the orignal.txt. Assume the contents…
vivek
  • 467
  • 2
  • 6
  • 18
0
votes
2 answers

Does advisory file locking work with default file descriptors?

For example, say I have the following shell command. ~]$ foobar 2>> foobar.log The above command redirects the standard error output (stderr, or file descriptor 2) to the file foobar.log, appending the output (the >> rather than just >). Now,…
magnus
  • 4,031
  • 7
  • 26
  • 48
0
votes
1 answer

silverstripe 3.x fcntl causing performance issues

I have a Silverspripe Page with a sports Liveticker and a RestAPI for iOS and Android App. Every call I make that is Not in the static cache makes some System calls setting a filelock. I have this function in my jsonapi Controller: function…
0
votes
1 answer

File locking in Python with fcntl

I am trying to define functions to ease the locking of files with the fcntl module. When I manually run fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB) in two separate instances of Python, I get the expected exception BlockingIOError: [Errno…
Gavin Kirby
  • 43
  • 10
0
votes
0 answers

How to write to stdin more than one times in python?

I create a subprocess in python3. p = subprocess.Popen('./a', stdin=subprocess.PIPE) And I want to write to it stdin. p.stdin.write('1\n') do_something() p.stdin.write('2\n') But python only support write once. What should I do? Should I use…
qin
  • 1,627
  • 15
  • 22