1

I was studying about the internals of Linux where I came to know about how the file descriptors of processes are kept under /proc/PID/fd. I tried to poke around an Ubuntu 18.04 installation and came across something that I cannot wrap my head around.
I have a chromium-browser process (pid 6949), for which exists a thread (pid 6961) that I confirm using htop.

The image attached below shows the output of 3 commands.

  1. No directory/file named 6961 exists.
  2. I have a hunch that I might not be allowed to read the location, so I try my luck with sudo, directory doesn't exist.
  3. I change directory to 6961 and it allows me a change!

I'm unable to understand why ls didn't list the directory named 6961 if there exists a valid location that I can cd to.
I also tried using flags -a, -h, and -l but ls simply does not list the directory /proc/6961.

What am I missing here?

akhil@hobbes:/proc$ ls /proc | grep 6961
akhil@hobbes:/proc$ sudo ls /proc | grep 6961
akhil@hobbes:/proc$ cd /proc/6961
akhil@hobbes:/proc/6961$
1
  • Wow, it looks it is the same on my Ubuntu, too. I suspect it is the intended behavior. Thread handling has a long, bloody history on Linux, and similarly the nuances of the behavior of /proc. Don't worry, your system is okay. I hope you get a more detailed answer as well.
    – peterh
    Mar 18, 2019 at 17:54

1 Answer 1

1

The explanation of this behavior can be found in the proc(5) manual page. Here is a shortened version of the Overview section:

   /proc/pid subdirectories
          ...

          The /proc/pid subdirectories are visible when iterating
          through /proc with getdents(2) (and thus are visible when
          one uses ls(1) to view the contents of /proc).

   /proc/tid subdirectories
          ...

          The /proc/tid subdirectories are not visible when
          iterating through /proc with getdents(2) (and thus are not
          visible when one uses ls(1) to view the contents of
          /proc).

Processes (threads whose thread IDs are equal their process IDs) can be seen under /proc using ls. Other threads are not visible using ls, but their directories can be accessed when their path is specified.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .