How to parse /proc/pid/cmdline

前端 未结 7 1930
盖世英雄少女心
盖世英雄少女心 2021-02-01 18:51

I\'m trying to split the cmdline of a process on Linux but it seems I cannot rely on it to be separated by \'\\0\' characters. Do you know why sometimes the \'\\0\' character is

7条回答
  •  一个人的身影
    2021-02-01 19:45

    Super-simple (but for only one process, not bulk parsing, etc):

    $ cat /proc/self/cmdline "a b" "cd e" | xargs -0
    

    How it works: by default, xargs just echo'es its input, and switch -0 allows it to read null-separated lines rather than newline-separated ones.

提交回复
热议问题