I learned that,in linux fork() is used to create a new process. It allocates new memory for the child process then copies data from parent process to the child process such as file descriptors. Then exec() can be used to load its own data and overwrite the process space. But I wonder is it necessary to copy data of parent process to child process?
I would like to be able to get a list of all of the file descriptors (now considering this question to pertain to actual files) that a process ever opened during the runtime of the process. The problem with polling /proc/(PID)/fd/ is that you only get a snapshot in time of what is currently open.
Assume the OS is linux. Suppose I opened a file for write and get a file descriptor fdw. Is it possible to get another file descriptor fdr, with read-only access to the file without calling open again?
I am trying to use shm_unlink(object_path) to clear up the shared memory I opened in signal handling function. However, the code doesn't work. What goes wrong? The code basically does this: A parent process is taking two integers from user input, and fork a child to compute the sum of the two. Once the sum is computed, the child informs the parent that it's done computing sum through a pipe.
I want to redirect stdin/stdout to some file. The program is being written for Unix OS but I think using standart C/C++ library instead of OS functions is good. I know how I can do that using OS functions dup2() and open() but I read some ways to do that using reopen() on stdin or stdout. Will reopening standart variables do what I want? Will it replace files opened at 0 and 1 file descriptors?
em trying to evaluate an expression in the child process and print the result from the parent process but even after using pipes em unable to even just print a message sent by child process.
here is what em doing:
using namespace std;