This is a subtle problem I find today. The ps
command can show command arguments for a process, but I find the feature crippled.
For a shell command line like this:
gdbserver localhost:5050 testg "hello world" 123
We know that gdbserver
's main()
will see:
argv[] | C string |
---|---|
argv[1] | localhost:5050 |
argv[2] | testg |
argv[3] | hello world |
argv[4] | 123 |
However, ps -ef
shows
gdbserver localhost:5050 testg hello world 123
So it looks like argv[3]
is hello
, which is so misleading.
So may question is clear, is there way to have ps show genuine argv[]
values? man ps
does not seem to refer to this issue. If it can't, any alternative tools?
No, PS can not (I think), but you can get it from proc e.g.
/proc/PID/cmdline
the cmdline file is a null separated list of the args of a program so this script will parce ithexdump -v -e '/1 "%02X "' /proc/PID/cmdline
will dump the file as hex each bite has a space in between it.sed 's/00/0a/g'
replaces the 00 (null) with 0a (line ending or new line)xxd -r -p
takes the hex and converts it back to binary So the output will be a list of args with a new line in between them.