Skip to contentSkip to conversation

proc.5: Clarify the format of /proc/$PID/cmdline

PATCH In review Günther Noack 2 participants 2 messages May 24, 2023 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc.5: Clarify the format of /proc/$PID/cmdline

It is possible to produce /proc/$PID/cmdline files which do not follow the NUL-seperated format, by using the tricks described in the paragraph below.

---
 man5/proc.5 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
man5/proc.5 +13 -2
index a9bb175e8..a16479634 100644
@@ -497,10 +497,21 @@ unless the process is a zombie.
 .\" In Linux 2.3.26, this also used to be true if the process was swapped out.
 In the latter case, there is nothing in this file:
 that is, a read on this file will return 0 characters.
-The command-line arguments appear in this file as a set of
-strings separated by null bytes (\[aq]\e0\[aq]),
+.IP
+For processes which are still running,
+the command-line arguments appear in this file
+in the same layout as they do in process memory:
+If the process is well-behaved,
+it is a set of strings separated by null bytes (\[aq]\e0\[aq]),
 with a further null byte after the last string.
 .IP
+This is the common case,
+but processes have the freedom to override
+the memory region and break assumptions
+about the contents or format of the
+.IR /proc/ pid /cmdline
+file.
+.IP
 If, after an
 .BR execve (2),
 the process modifies its

base-commit: 4ca216bacc7d185c1af3c384ab53cd1ec74830d1

Signature · 1 line
2.40.1.698.g37aff9b760-goog
#1 lore raw

Hi Günther!

Quoted 5 lines · Günther Noack

It is possible to produce /proc/$PID/cmdline files which do not follow the NUL-seperated format, by using the tricks described in the paragraph below.

Thanks! Patch applied.

Cheers,
Alex

Quoted 34 lines
---
 man5/proc.5 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
man5/proc.5 +13 -2
index a9bb175e8..a16479634 100644
@@ -497,10 +497,21 @@ unless the process is a zombie.
 .\" In Linux 2.3.26, this also used to be true if the process was swapped out.
 In the latter case, there is nothing in this file:
 that is, a read on this file will return 0 characters.
-The command-line arguments appear in this file as a set of
-strings separated by null bytes (\[aq]\e0\[aq]),
+.IP
+For processes which are still running,
+the command-line arguments appear in this file
+in the same layout as they do in process memory:
+If the process is well-behaved,
+it is a set of strings separated by null bytes (\[aq]\e0\[aq]),
 with a further null byte after the last string.
 .IP
+This is the common case,
+but processes have the freedom to override
+the memory region and break assumptions
+about the contents or format of the
+.IR /proc/ pid /cmdline
+file.
+.IP
 If, after an
 .BR execve (2),
 the process modifies its

base-commit: 4ca216bacc7d185c1af3c384ab53cd1ec74830d1

Signature · 2 lines
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5