General
cancel
Showing results for 
Search instead for 
Did you mean: 

ps -efx showing truncated result for command column

 
Thrifty
Visitor

ps -efx showing truncated result for command column

Hey Guys,

I'm having a bit of an issue when ps, I'm getting truncated results for  the command column.

It was mentioned on other posts here to try use the -x flag which resulted in more of the command being showed but still has a chunk cut off.

Anyone know why this is happening or if there is a work around I can possibly do to check the full command for a process in it's entirety.

3 REPLIES 3
Highlighted
Bill Hassell
Honored Contributor

Re: ps -efx showing truncated result for command column

The ps command was not (originally) designed for massive command line strings. Before HP-UX 11.00 (ie, 10.20, etc), you were stuck with about 46 characters and no -x for extended command line. At 11.00, the -x feature was a patch to ps but limited to 1000 characters. Extremely long command lines can run into a number of OS and/or shell string limitations.

The man page is helpful:

 

      The default length of the COMMAND field is 128 (including the null
      terminator).  This can be configured by setting
      DEFAULT_CMD_LINE_WIDTH=value in the /etc/default/ps file.  The value
      of DEFAULT_CMD_LINE_WIDTH should be between 64 and 1020.  However,
      when the comm column is displayed, by default, the length of the
      COMMAND field will be 14 characters.  If the environment variable
      PS_CMD_BASENAME is defined, then the length of the COMMAND field will
      be between 64 and 255 characters.

 

 



Bill Hassell, sysadmin
Thrifty
Visitor

Re: ps -efx showing truncated result for command column

So the ps command will always have a limit of 1020 characters, would you happen to know of any other means to see the full command via other commands, I was looking at pstat but that also seems to have the same limit? 

ranganath ramachandra
Esteemed Contributor

Re: ps -efx showing truncated result for command column

If you have the privileges to attach a debugger to the process, you could hack into libc's __argv:

#! /bin/sh
echo $(\
{
cat <<EOF
set print elements 0
set print address off
set pagination off
set \$argc=1
set \$argv=(char **)__argv
while \$argv[\$argc] != 0
  print \$argv[\$argc]
  set \$argc=\$argc+1
  end
quit
EOF
} \
| gdb -q -p $1 \
| grep = \
| sed -e 's/^[^=]*=//g' -e 's/"//g'\
)

You could do it with a C program using ttrace(2) calls (to attach to the process and to read process data) and cross-process libdl calls (to resolve "__argv") etc.

 
--
ranga
(i work for hpe)