The Hidden PS

2010-11-27 314 words 2 mins read

  <td>
    <div class="text codecolorer">
      &nbsp;for p in `ps L|cut -d' ' -f1`;do echo -e "`tput clear;read -p$p -n1 p`";ps wwo pid:6,user:8,comm:10,$p kpid -A;done
    </div>
  </td>
</tr>
1

While going through the source code for the well known ps command, I read about some interesting things.. Namely, that there are a bunch of different fields that ps can try and enumerate for you. These are fields I was not able to find in the man pages, documentation, only in the source.

Here is a longer function that goes through each of the formats recognized by the ps on your machine, executes it, and then prompts you whether you would like to add it or not. Adding it simply adds it to an array that is then printed when you ctrl-c or at the end of the function run. This lets you save your favorite ones and then see the command to put in your .bash_profile like mine at : http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

Note that I had to do the exec method below in order to pause with read.

  <td>
    <div class="text codecolorer">
      t ()<br /> <br /> {<br /> <br /> local r l a P f=/tmp/ps c='command ps wwo pid:6,user:8,vsize:8,comm:20' IFS=' ';<br /> <br /> trap 'exec 66<br /> <br /> exec 66 $f && command ps L | tr -s ' ' >&$f;<br /> <br /> while read -u66 l >&/dev/null; do<br /> <br /> a=${l/% */};<br /> <br /> $c,$a k -${a//%/} -A;<br /> <br /> yn "Add $a" && P[$SECONDS]=$a;<br /> <br /> done<br /> <br /> }
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

* View this command to comment, vote or add to favourites * View all commands by AskApache

commandlinefu.com

by David Winterbottom (codeinthehole.com)

Gmail Twitter Facebook Delicious Tumblr 1 person recommended this

Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it