Does Linux automatically release an unnamed pipe when both file descriptors are closed?

I use an unnamed channel for interprocess communication between a parent process and a child process created through fork (). I use the pipe () function included in unistd.h

I would suggest that once both file descriptors were closed (and in both processes), that the channel is freed / freed / destroyed / etc. But I did not find anything on the manual pages that finally confirm this. I am making a program that will work for a very long time, so I want to prevent memory leaks and other things of this kind.

The body of my function looks something like this:

int pipefds[2];

pipe( pipefds );

if ( fork() == 0 ) {

    close( pipefds[1] );
    ...
    //Use pipefds[0]
    close( pipefds[0] );

} else {

    close( pipefds[0] );
    ...
    //Use pipefds[1]
    close( pipefds[1] );
}

, , , , // /etc.

- , ?

+5
3

http://www.opengroup.org/onlinepubs/009695399/functions/close.html

FIFO , , FIFO .

, , gubbins - ", ", , , ​​ , : -)

+6

close .

 The close() call deletes a descriptor from the per-process object reference
 table.  If this is the last reference to the underlying object, the
 object will be deactivated.
+5

Well, the only thing you can do is close both ends of the pipe, right? Yes, the pipe will be released after all handles at both ends of the pipe are closed.

0
source