Your Location is: Home > Linux-kernel

Does the close() system call close all references to the file?

From: Yemen View: 2471 Hanik 

Question

Let's say we have a pipe, my_pipe, which occupies file descriptors at entries 3 and 4 of the process's FDT (initial FDT scheme)

  1. First, we close the stdout standard output stream using close(1) (updated FDT scheme).
  2. Next, using dup(my_pipe[1]), we create a copy of the pipe's writing end file descriptor at the lowest available FDT entry - in our case entry 1, which was made available in the previous step.
    my_pipe[1] is now referred to by both entry 1 and entry 4 (updated FDT scheme).
  3. The following command we run is close(my_pipe[1]).

My question is - which of the file descriptors referring to my_pipe[1] will close?

Best answer