Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

overcoming the 80 character limitation of solaris ps

by Anonymous Monk
on Jun 26, 2002 at 18:43 UTC ( [id://177471]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have got some scripts that rely on the output of the "ps" command.
Upon migrating them to a solaris environment, I discovered that the standard solaris "ps" command limits the output of the commandline to 80 characters, which is not enough in some cases.

Are there alternatives in perl to read the process-table ?

I have already tried Proc::ProcessTable, which unfortunately has the same limitation.

I am sure that the limitation is not in the kernel itself, as the BSD-style ps (/usr/ucb/ps) displays the whole commandline.
I cannot use this though, because whenever the output of this command is redirected, it is cut off, too.

Thanks,
        Kurt
  • Comment on overcoming the 80 character limitation of solaris ps

Replies are listed 'Best First'.
Re: overcoming the 80 character limitation of solaris ps
by hossman (Prior) on Jun 26, 2002 at 19:08 UTC
    try...

    /usr/ucb/ps -w

    Or...

    /usr/ucb/ps -www

    (ie: Wide Wide Wide)

    abv-sfo1-x-app58:~> /usr/bin/ps -p 5136 PID TTY TIME CMD 5136 pts/32 0:33 java abv-sfo1-x-app58:~> /usr/ucb/ps 5136 PID TT S TIME COMMAND 5136 pts/32 S 0:33 /usr/local/depot/j2sdk-1.3.1_01/usr/j2se/bin/. +./bin/spa abv-sfo1-x-app58:~> /usr/ucb/ps -w 5136 PID TT S TIME COMMAND 5136 pts/32 S 0:33 /usr/local/depot/j2sdk-1.3.1_01/usr/j2se/bin/. +./bin/sparc/native_threads/java -server -native -ms64m -mx64 abv-sfo1-x-app58:~> /usr/ucb/ps -www 5136 PID TT S TIME COMMAND 5136 pts/32 S 0:33 /usr/local/depot/j2sdk-1.3.1_01/usr/j2se/bin/. +./bin/sparc/native_threads/java -server -native -ms64m -mx64m -classp +ath ./lib/weblogic510sp10boot.jar:./classes/boot -Dfile.encoding=iso- +8859-1 -Dweblogic.class.path=./lib/weblogic510sp10.jar:./license:./cl +asses:./lib/weblogicaux.jar:./server-7022/serverclasses:./server-7022 +/lib/activation.jar:./server-7022/lib/avs30.jar:./server-7022/lib/cos +.jar:./server-7022/lib/jakarta-oro-2.0.2-dev-2.jar:./server-7022/lib/ +jakarta-regexp-1.0.jar:./server-7022/lib/jconn2.jar:./server-7022/lib +/mail.jar -Dweblogic.home=. -Djava.security.manager -Djava.security.p +olicy==/var/httpd/weblogic-5.1.0/weblogic.policy -Dweblogic.system.na +me=server-7022 weblogic.Server
      Thank you, that was exactly the advise I needed !

      Beeing curious, I wonder if you know why /usr/ucb/ps prints the full commandline, but when redirecting its output, the -www switch is needed ?

      thanks,
             Kurt
        (first of all, i realize now that -ww is usually all you need -- i can't remember why, but some where i got it in my head that on some systems, you need -www)

        I don't have any documentation to back this up, but as i understand it, this is what happens:

        • If /usr/ucb/ps has no idea where it's output is going (ie: you are redirecting it, or on a dumb terminal) then it follows the strict definition in the manpage: 80 chars, unless you use -w in which case it's 132 chars, unless you use -ww(w) in which case it's as wide as possible.
        • If you are using a non-dumb terminal, and /usr/ucb/ps can determine your terminal width, then it will use that width by default. if you use -w (or -ww or -www) it will output as much as possible

        you probably aren't really seeing -w truncated to 80 characters when you pipe it -- you're probably seeing it truncated to 132, which is all -w is documented to give you.

Re: overcoming the 80 character limitation of solaris ps
by Aristotle (Chancellor) on Jun 26, 2002 at 18:54 UTC
    Just a blind potshot: GNU ps has the option -w (wide) for this. Maybe Solaris' has something similar.

    Makeshifts last the longest.

Re: overcoming the 80 character limitation of solaris ps
by kjherron (Pilgrim) on Jun 26, 2002 at 21:07 UTC
    If you're interested in the gory details, check out the proc(4) man page ("man -s4 proc"), specifically the psinfo and as files. psinfo contains two things to help you:
    1. The first 80 characters of the original command line, basically, the string that /usr/bin/ps prints.
    2. The address of the process's original argument list, within its address space. By opening the as file and seeking to this address, you can read the arg list out of the process's address space.
    In principle, you could use perl to do either of these things. Hopefully you're familiar with pack and unpack.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://177471]
Approved by waggerz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found