Why is sysctl producing E_INVAL on Mac OS X?

前端 未结 1 429
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 03:33

Below is a pared-down (error/null checks omitted) snippet of C/Obj-C code that uses sysctl to get the argv of a particular process with PID 50.

...
int getProces         


        
相关标签:
1条回答
  • 2021-01-27 03:43

    I tried wrapping your code up into a program, and it works fine and prints out the other process's argv etc when inquiring about one of my own processes, i.e., one with the same uid as the process invoking sysctl().

    The "larger than I would expect" aspect is because the process's environment variables are returned as well as the command line arguments. (It's not obvious what the format of all this information is.)

    When inquiring about a different user's process, I get the same EINVAL from the second sysctl that you've been seeing. I guess this is considered unreasonable curiosity about other people's processes, but you'd think the first sysctl would fail too.

    (When inquiring about a non-existent pid, the first sysctl fails with EINVAL.)

    This all seems to be massively underdocumented: on Leopard, KERN_PROCARGS doesn't even appear in the sysctl man page.

    0 讨论(0)
提交回复
热议问题