Assuming a plain text file, foo.txt, and two processes: Process A, a shell script, overwrites the file in regular intervals $ echo “example” > foo.txt Process B, a C program, reads from the file in regular intervals fopen(“foo.txt”, “r”); getline(buf, len, fp); fclose(fp); In the C program, keeping the FILE* fp open after the initial fopen(), doing a rewind() and
Tag: file
How does the command ‘echo “6” > /proc/sys/kernel/printk’ work?
Please see an example in How can I show printk() message in console?, If the /proc/sys/kernel/prink was a normal file, the file would have changed to just “6”, a single number. But I know the proc file system is a file system in ram and I guess it works different. In what mechanism did the file changed that way? And
Close file in C
Under Linux I use this code to redirect stdout and stderr on a file, as shown in the code the file is opened using fopen(f) and is it closed using close(fd). My question is whether the close(fd) statement closes all file descriptors, or is it necessary to use fclose(f) as well ? Answer The rule is to close the outermost
linux_rename files in directory by prepending with timestamp using find command
I am trying to rename files in current directory by prepending timestamp value using find command like below But getting ‘Can’t move, no such file or directory error’, but appending works well with below command, not sure what is the difference between two. Answer Try this
Protecting against Time-of-check to time-of-use?
I was reading: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use They showed this code to be buggy and I totally understand why it’s so: But the real question is how to protect against this type of exploits? Answer You can use the O_NOFOLLOW flag. It will cause the open to fail if basename of the path is a symbolic link. That would solve the described attack.
Permission denied – Even tho in group with ownership [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
Quickly create an uncompressible large file on a Linux system
On a Linux system, I need to create a large file (about 10GB), uncompressible file. This file is supposed to reside in a Docker image, needed to test performance in transferring and storing large docker images on a local registry. Therefore, I need the image to be “intrinsically” large (that is: uncompressible), in order to bypass optimization mechanisms. fallocate (described
Linux Sort words alphabetically and make a file for each letter
I want to write a shell script which creates automatically 26 dictionary files, where the first file should contain all the words starting with a or A, the second all the words starting with b or B, … etc. Where each dictionary file is sorted. For example, if I had a file that had the words Lime, Apple, Orange, Avacado,
My file doesn’t return the magic file message
I have to create a magic file that can detect a result of 42 on the 42nd byte. I’ve created the following line to then compile but when I run file -m <file_name> with this content I get the message Answer Your magic should be like this: Here’s my test:
Copy a file from one directory to another in C++
I am writing a C++ program to copy one file from one directory to another. I don’t want to use C++ 17 features. I have already implemented this in the following code. I am on Linux and I want to use the OS cp command to do this. I have written this code. The error is: cp: source: No such