file-descriptor

C freopen descriptor - close manually/leave opened

岁酱吖の 提交于 2021-02-19 06:01:33
问题 I've been using freopen (from stdio.h) function before without asking myself this question. But now I'm unsure. E.g. I've reopened stdout: #define OUTPUT_FILE "out.txt" if ( freopen(OUTPUT_FILE,"w+",stdout) == NULL) printf("logout can't be opened\n"); Usually every process has and handles stdout, stderr, stdin automatically and we needn't care about closing of them. But how is it to be here? I have reopened stdout. Should I call fclose for closing reopened stdout? PS I'd be gladder to look at

Nested while read loops with fd

混江龙づ霸主 提交于 2021-02-19 04:04:13
问题 I'm trying to read from two different inputs in nested loops without success. I've followed the best answer on this question and also took a look at the file descriptors page of the Advanced Bash-Scripting Guide . Sample script I made to test my problem. #!/bin/bash while read line <&3 ; do echo $line while read _line <&4 ; do echo $_line done 4< "sample-2.txt" done 3< "sample-1.txt" Content of sample-1.txt Foo Foo Content of sample-2.txt Bar Bar Expected output Foo Bar Bar Foo Bar Bar The

How should I manage ::std::cout after changing file descriptor 1 to refer to a different file?

随声附和 提交于 2021-02-19 01:22:37
问题 I would like to do dup2(fd, 1); close(fd); and have ::std::cout write to the new fd 1. How do I can reset the state of ::std::cout so nothing goes funny? For example, is flushing beforehand sufficient? Or is there more to do than that? I'm also curious about the same thing with ::std::cin . Is there a standard mechanism for resetting these if you change out the file descriptors they're using underneath them? To be clear, my goal here is basically to redirect my own input and output someplace

Encrypt video on the fly from android camera

百般思念 提交于 2021-02-18 11:14:26
问题 I want to encrypt video on the fly that android camera captures. So I need to tell android MediaRecorder to write it video stream to my CipherOutputStream . The problem is MediaRecorder.setOutputFile() method accepts only FileDescriptor and there is no way to get encrypting file descriptor from CipherOutputStream. So my question is how can I either emulate FileDescriptor to receive data writes and do encryption manually or somehow convince MediaRecorder to stream video into CipherOutputStream

What happens when you call close() on a pipe file descriptor that was duplicated with dup2()?

两盒软妹~` 提交于 2021-02-17 04:52:34
问题 I have a question regarding file descriptors in Unix and C programming. Let's say I use pipe(fd) to get file descriptor 3 and 4 for the pipe ends, 3 connects to the read end and 4 to the write end. Now I use dup2(fd[write_end],1) to copy the descriptor of the write end (which was 4) to file descriptor 1 in my process. If I now do close(fd[write_end]) will it close descriptor 1 or descriptor 4? 回答1: After a successful call to dup2 , both file descriptors are valid. When you then call close(fd

boost::process system leaking file descriptors

夙愿已清 提交于 2021-02-10 03:10:13
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

boost::process system leaking file descriptors

帅比萌擦擦* 提交于 2021-02-10 03:08:44
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

boost::process system leaking file descriptors

一笑奈何 提交于 2021-02-10 03:07:58
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

How can I pass a socket from parent to child processes

不打扰是莪最后的温柔 提交于 2021-02-07 05:33:58
问题 I'm stuck on a problem in a C program on Linux. I know that when a processes is forked the child process inherits some things from the parent, including open file descriptors. The problem is that I'm writing a multi-process server application with a master process that accepts new connections and puts the descriptors into shared memory. When the child process attempts to read from one of these descriptors from the shared memory, on select() i got an EBADF error! How can the child process read

FFmpeg: seeking not possible with file descriptor on Android Q

↘锁芯ラ 提交于 2021-02-06 10:44:13
问题 Given the fact that public file paths will generally not be available in Android Q with scoped storage, I am attempting to figure out how to make my FFmpeg audio decoder work with file descriptors, without copying the file to my app's private directories. We can easily get a file descriptor using the methods described in Android Q privacy changes, and it is possible to open the file descriptor using the pipe protocol as described in Passing a native fd int to FFMPEG from openable URI. However