Open myk002 opened 9 months ago
I do not recommend scanning ps
output because that won't handle whitespace in arguments properly.
On Linux, we'd probably be better off reading /proc/<pid>/cmdline
.
proc
works for Linux. I was hoping to have a single solution for all of Unix, and scanning ps
output is what was recommended by various internet advice posts, e.g. https://stackoverflow.com/questions/821837/how-to-get-the-command-line-args-passed-to-a-running-process-on-unix-linux-syste#:~:text=For%20Linux%20%26%20Unix%20System%20you,get%20the%20full%20command%20line.
also a reminder that on all remotely recent versions of linux /proc/self
refers to the running process, so you don't have to do sprintf(buf, "/proc/%d/cmdline", getpid())
if you don't want to (and you absolutely shouldn't want to), you can just grab /proc/self/cmdline
i found a suggestion on the web of using _NSGetArgc
and _NSGetArgv
for this purpose in OSX; the source where i found this says that these are undocumented so ymmv
scanning ps
output is the only solution known for solaris or freebsd (and on solaris at least it's imperfect, and to get the true command line you have to be super-user), but these platforms aren't relevant to our use case so i wouldn't worry about it
so missing globals or misaligned structures won't immediately crash the game
Use GetCommandLineA on Windows https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getcommandlinea
on unix, scan the output of
ps -p <pid> -o command=