Skip to contentSkip to conversation

Document /proc/TGID /proc/TID readdir weirdness

PATCH New Nikanth Karthikesan 1 participant 1 message Jul 14, 2009 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Document /proc/TGID /proc/TID readdir weirdness

readdir() on /proc returns only one directory per TGID, i.e., /proc/<TGID> But if you, try to read a directory /proc/<TID>/ where there is no TGID == TID, it would succeed.

For example,

$ ls /proc
There is no directory by name /proc/6375
$ ls /proc/6373/task
6373  6375
$ ls /proc/6375/
attr        cmdline          environ  io        maps ...
/proc/6375/ exists!

I tried changing this behaviour to disallow reads using /proc/<TID>/, but it breaks, a lot of user-space applications and scripts that depend on this behaviour. So let us make this a documented behaviour.

---

Documentation/filesystems/proc.txt +6 -0
index fad18f9..ae79898 100644
@@ -137,8 +137,14 @@ Table 1-1: Process specific entries in /proc
  stack		Report full stack trace, enable via CONFIG_STACKTRACE
  smaps		a extension based on maps, showing the memory consumption of
 		each mapping
+ task		Contains directories for each thread in this thread group. Each
+		of those directory contain similar information specific for
+		those threads. /proc/<TGID>/task/<TID>
 ..............................................................................
 
+NOTE: Even though readdir() on /proc returns only one directory per TGID it is
+possible to open and read /proc/<TID>/ directly, using any TID as well.
+
 For example, to get the status information of a process, all you have to do is
 read the file /proc/PID/status: