0

I have created a second process P2 using popen from first process P1.

and there were few open file descriptors in the P1. those open fd now become shared by other process as well P2. so what happened is P2 has created a file descriptor of its own and that refer to the open file of P1. It is happening Since open files are shared in case of popen".

I need to close P1 process, but before that I want to close all the shared file descriptors which was opened by P2.

Abhishek

akure
  • 49
  • 1
  • 7
  • Your question is a bit of unclear. What actually hinders you to close the fd's with `pclose()`? – πάντα ῥεῖ Jul 04 '14 at 10:22
  • suppose there is a file F1 which is already open by P1. and P1 now spwan the P2. now what is happening is that P2 also opens a fd and associate that with the F1. now if I close the F1 in P1. it will not close the F1 fd in P2. – akure Jul 04 '14 at 10:27
  • 1
    Have you considered using fcntl as described [here][1]? fcntl(fd, F_SETFD, FD_CLOEXEC) [1]: http://stackoverflow.com/questions/6599420/linux-how-to-mark-a-file-descriptor-as-not-inheritable-on-fork – Manuel Barbe Jul 04 '14 at 11:18

0 Answers0