2

I am thinking about working with the /proc/<pid>/cmdline files, but I couldn't find any documentation about the file encoding. The only piece of information I could find is located in the man page:

 /proc/[pid]/cmdline
    This holds the complete command line for the process, unless the process is a zombie.  In the  latter
    case, there is nothing in this file: that is, a read on this file will return 0 characters.  The com‐
    mand-line arguments appear in this file as a set of strings separated by null bytes  ('\0'),  with  a
    further null byte after the last string.

What is the encoding of the cmdline file?

1 Answers1

4

The command-line arguments appear in this file as a set of strings separated by null bytes ('\0'), with a further null byte after the last string.

It is all you need. You have got command and its arguments separated by null byte \0. Encoding of the characters is based on the locale, but it should not really matter.

Do you have some specific example where you need help?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Jakuje
  • 21,357
  • I think I need to understand "why it should not really matter" as I am probably missing something here. Can the cmdline only consist of ASCII characters? – TommyMason Jan 29 '16 at 08:48
  • 2
    Yes. It should not matter, because the command line usually contains only ASCII. And if not, you have locale (LANG variable is in /proc/<pid>/environ). – Jakuje Jan 29 '16 at 08:54
  • 1
    @BenR It's arbitrary non-null bytes exactly as provided when launching the program. It may not be text at all. – Michael Homer Jan 29 '16 at 09:12
  • @MichaelHomer: Now it gets interesting! :) Do you have any pointers / man pages that I could use to read up on this topic? I was under the assumption that a cmdline needs to be a character sequence. – TommyMason Jan 29 '16 at 09:29
  • Everything is bytes. Otherwise you'd have files you could never refer to. – Michael Homer Jan 29 '16 at 09:35