I think I use this program more than any other. I bet the readers here can help me think of cool ways to make it better. ;) Keep in mind, that this was one of the very first programs I ever wrote in perl--so it's pretty bad. I very nearly tried this one in C.

This also used to come with a program called irun, but it was really just a 'psall | head -1; psall | grep $USER'. :)

#!/usr/bin/perl use Term::Size; $psl=`ps auxfw`; @psla=split("\n", $psl); ($width, undef) = Term::Size::chars; $Iam=getpwuid($<); foreach $l (@psla) { %clen = ( "user" => 8, "pid" => 5, "pcpu" => 4, "pmem" => 4, "size" => 5, "rss" => 5, "tty" => 5, "stat" => 3, "start" => 6, "time" => 5, ); %proc = ( "user" => substr($l, 0, $clen{"user"} ), "pid" => substr($l, 9, $clen{"pid"} ), "pcpu" => substr($l, 15, $clen{"pcpu"} ), "pmem" => substr($l, 20, $clen{"pmem"} ), "size" => substr($l, 25, $clen{"size"} ), "rss" => substr($l, 31, $clen{"rss"} ), "tty" => substr($l, 36, $clen{"tty"} ), "stat" => substr($l, 41, $clen{"stat"} ), "start" => substr($l, 45, $clen{"start"} ), "time" => substr($l, 53, $clen{"time"} ), "cmd" => substr($l, 63 ) ); $_ = $proc{"user"}; if ( /root/ ) { $usercolor = "^[[0;31m"; } elsif ( /$Iam/ ) { $usercolor = "^[[0;34m"; } else { $usercolor = "^[[0;36m"; } @out = ( $usercolor, $proc{"user"}, "^[[0;33m", $proc{"tty"}, " ", "^[[1;30m", $proc{"pid" }, " ", "^[[0;37m", $proc{"pcpu"}, " ", "^[[1;37m", $proc{"pmem"}, " ", "^[[1m", $proc{"cmd" } ); $out = substr join("",@out), 0, ($width+(7*6)-3); print $out, "\n"; } #USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND #012345678901234567890123456789012345678901234567890123456789012345678 +90123456 # 1 . . 2 . .3 . .4 . 5 . 6 + 7

#shandor    986  0.0  0.0  1752    0 pts/0    SW   16:54   0:00      \_ [bash]

In reply to psall (color ps) by jettero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.