Do user processes keep a file descriptor for the executable file itself, and for shared libraries? For example, if I look into /proc/PID/fd of bash, I expected to see at least the following fds, besides stdin/stdout/stderr:

  1. one for /usr/bin/bash
  2. one for /usr/lib/XXX/libc-2.XX.so file.

According to kernel function load_elf_binary, it does seem to be the case that a fd is allocated for the executable at least.

However, in reality I didn't find such fds in /proc/PID/fd folder, likely because they do not exist in task_struct->files->fd_array. So the questions are:

  1. does kernel store pointers to the file objects that corresponds to the executable, and the shared libraries, in a per process struct such as task_struct/thread_info?
  2. if so, which struct?

No, there's not file descriptors for those things in general. However, there is /proc/PID/exe that shows you what binary is running, and /proc/PID/maps and /proc/PID/map_files/ that shows you what's mapped where. Also, even if these things didn't exist, the kernel can still keep track of it. Not everything in the kernel's memory is exposed via /proc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.