Get a process's command line
Read a running process's full command line from /proc/PID/cmdline. The arguments are separated by NUL bytes, so split them with xargs -0 and not tr.
ps truncates long command lines and loses the boundaries between arguments, but the kernel keeps the exact list.
python3 -c 'import time; time.sleep(60)' first "second arg" &
pid=$!
tr '\0' ' ' < /proc/$pid/cmdline; echo
xargs -0 printf '[%s]\n' < /proc/$pid/cmdline
kill $pidpython3 -c import time; time.sleep(60) first second arg
[python3]
[-c]
[import time; time.sleep(60)]
[first]
[second arg]The kernel exposes the argument vector of a process in /proc/PID/cmdline as the strings joined by NUL bytes, as the proc manual explains. Turning the NULs into spaces, as the first command does, merges "second arg" into two words. xargs -0 splits on the NULs, so each argument stays whole.
A process can rewrite its own argv after it starts, so what you read may differ from what was typed. The file is empty for a zombie and for kernel threads, and it is readable by any user unless the system mounts /proc with hidepid. Parsing it is Linux only.