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
  • That seems like pretty complete documentation on the encoding... Commented Jan 29, 2016 at 8:30

1 Answer 1

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?

5
  • 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
    Commented Jan 29, 2016 at 8: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
    Commented Jan 29, 2016 at 8:54
  • 1
    @BenR It's arbitrary non-null bytes exactly as provided when launching the program. It may not be text at all. Commented Jan 29, 2016 at 9: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
    Commented Jan 29, 2016 at 9:29
  • Everything is bytes. Otherwise you'd have files you could never refer to. Commented Jan 29, 2016 at 9:35

You must log in to answer this question.

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