Q: HP-UX 11.31 & "ps -e" command length - HP UX

This is a discussion on Q: HP-UX 11.31 & "ps -e" command length - HP UX ; Hi, I found out why my script failed to find a running process in HP-UX 11.31: "ps -e" seems to display only the first 14 characters of the command, whatever DEFAULT_CMD_LINE_WIDTH is set. I can only hope that this is ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Q: HP-UX 11.31 & "ps -e" command length

  1. Q: HP-UX 11.31 & "ps -e" command length

    Hi,

    I found out why my script failed to find a running process in HP-UX 11.31:
    "ps -e" seems to display only the first 14 characters of the command, whatever
    DEFAULT_CMD_LINE_WIDTH is set.

    I can only hope that this is not a feature!

    OTOH, Linux (openSUSE 11.0) also just displays 15(!) characters for the
    command in "ps -e" output.

    Oh man, is this the age or arbitrary legth restrictions?

    So how would you improve

    PID=$(ps -e | awk '$NF == "'"$CMD"'" { print $1 }')

    to work for any command $CMD?

    Regards,
    Ulrich

  2. Re: Q: HP-UX 11.31 & "ps -e" command length

    Ulrich Windl a écrit :
    > "ps -e" seems to display only the first 14 characters of the command, whatever

    export UNIX95= (to work with XPG4 version of ps).
    and see option -o man page ps

  3. Re: Q: HP-UX 11.31 & "ps -e" command length

    "Alain" wrote in message
    news:48a065ee$0$2847$ba620e4c@news.skynet.be...
    > Ulrich Windl a écrit :
    >> "ps -e" seems to display only the first 14 characters of the command,
    >> whatever

    > export UNIX95= (to work with XPG4 version of ps).
    > and see option -o man page ps


    Still, don't expect to see very long commands - HP-UX uses a fixed buffer
    in it's process table to hold the command an args - 60+ chars is all you'll
    ever get.

    Dan Mercer


  4. Re: HP-UX 11.31 & "ps -e" command length

    "Ulrich Windl" wrote in message
    news:8763q764p5.fsf@pc9454.klinik.uni-regensburg.de...
    > Hi,
    >
    > I found out why my script failed to find a running process in HP-UX 11.31:
    > "ps -e" seems to display only the first 14 characters of the command,
    > whatever
    > DEFAULT_CMD_LINE_WIDTH is set.
    >
    > I can only hope that this is not a feature!
    >
    > OTOH, Linux (openSUSE 11.0) also just displays 15(!) characters for the
    > command in "ps -e" output.
    >
    > Oh man, is this the age or arbitrary legth restrictions?
    >
    > So how would you improve
    >
    > PID=$(ps -e | awk '$NF == "'"$CMD"'" { print $1 }')
    >
    > to work for any command $CMD?
    >
    > Regards,
    > Ulrich


    Does 'ps -ex' help?



  5. Re: Q: HP-UX 11.31 & "ps -e" command length

    Alain writes:

    > Ulrich Windl a écrit :
    >> "ps -e" seems to display only the first 14 characters of the command, whatever

    > export UNIX95= (to work with XPG4 version of ps).
    > and see option -o man page ps


    Oops!: "ps -e" and "UNIX95= ps -e" print completely different things! What
    astonishes me is that "UNIX95" is not set, and still "ps" behaves as if it is.

    Regards,
    Ulrich


  6. Re: Q: HP-UX 11.31 & "ps -e" command length

    "Dan Mercer" writes:

    > "Alain" wrote in message
    > news:48a065ee$0$2847$ba620e4c@news.skynet.be...
    >> Ulrich Windl a écrit :
    >>> "ps -e" seems to display only the first 14 characters of the command,
    >>> whatever

    >> export UNIX95= (to work with XPG4 version of ps).
    >> and see option -o man page ps

    >
    > Still, don't expect to see very long commands - HP-UX uses a fixed buffer
    > in it's process table to hold the command an args - 60+ chars is all you'll
    > ever get.


    OK, I was still thinking of "reasonable" names (my name is just one character
    too long). The problem, BTW, was found in the HA-NFS script from HP: I don't
    know why they first start a shell script in background and then use ps and grep
    to get the PID of that process when "$!" just has the PID. With the length
    limit of "ps -e" the script might select the wrong process(es), or find no
    process at all...

    On the 60-character-limit: To me it sounds reasonable to be able to query what
    you are able to start: If an exec syscall allows long command names, there
    should be a routine to retrieve those. I'd prefer exec() to return EINVAL if
    the command name is longer than HP-UX can handle.

    BTW: How does ps get the process list? Still reading kernel memory?

    Regards,
    Ulrich

  7. Re: HP-UX 11.31 & "ps -e" command length

    "Kilgaard" writes:

    [...]
    >> So how would you improve
    >>
    >> PID=$(ps -e | awk '$NF == "'"$CMD"'" { print $1 }')
    >>
    >> to work for any command $CMD?
    >>
    >> Regards,
    >> Ulrich

    >
    > Does 'ps -ex' help?


    No, it does not help, because "ps -e" outputs the command name without leading
    path (/usr/bin/...), while "ps -ex" outputs the command with patch and
    arguments. So you'd have to take care not to mix arguments with commands, like
    in the famous "ps -ef | grep sh".

    Regards,
    Ulrich

  8. Re: HP-UX 11.31 & "ps -e" command length

    Ulrich Windl wrote:
    > So you'd have to take care not to mix arguments with commands, like
    > in the famous "ps -ef | grep sh".


    It is illegal to use grep with ps in this way. Why not use:
    UNIX95=1 ps -f -C sh

    (Adding -x to this will give 1000 bytes.)

+ Reply to Thread