<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Ruby_sort_ps</id>
	<title>Ruby sort ps - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Ruby_sort_ps"/>
	<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Ruby_sort_ps&amp;action=history"/>
	<updated>2026-05-16T02:54:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0-beta</generator>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Ruby_sort_ps&amp;diff=1997&amp;oldid=prev</id>
		<title>Egge at 00:41, 31 July 2008</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Ruby_sort_ps&amp;diff=1997&amp;oldid=prev"/>
		<updated>2008-07-31T00:41:46Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:41, 31 July 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l47&quot;&gt;Line 47:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 47:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/geshi&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/geshi&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Ruby]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Ruby&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|sort ps&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Solaris]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Solaris]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key egge_wikimedia-mw_:diff:1.41:old-1807:rev-1997:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Egge</name></author>
	</entry>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Ruby_sort_ps&amp;diff=1807&amp;oldid=prev</id>
		<title>Egge: New page: Today I needed to sort ps by the total CPU time.  I also wanted to sum all the same type processes together.  Here&#039;s the script I came up with  &lt;geshi lang=&quot;ruby&quot;&gt; #!/bin/env ruby #  # Giv...</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Ruby_sort_ps&amp;diff=1807&amp;oldid=prev"/>
		<updated>2007-11-14T04:49:05Z</updated>

		<summary type="html">&lt;p&gt;New page: Today I needed to sort ps by the total CPU time.  I also wanted to sum all the same type processes together.  Here&amp;#039;s the script I came up with  &amp;lt;geshi lang=&amp;quot;ruby&amp;quot;&amp;gt; #!/bin/env ruby #  # Giv...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Today I needed to sort ps by the total CPU time.  I also wanted to sum all the same type processes together.  Here&amp;#039;s the script I came up with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/env ruby&lt;br /&gt;
# &lt;br /&gt;
# Given the output from &amp;#039;ps -o user,time,nlwp,fname&amp;#039; this script will sum the CPU time&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
header = nil&lt;br /&gt;
procs = {}&lt;br /&gt;
procs.default = 0&lt;br /&gt;
while((line = STDIN.gets)) &lt;br /&gt;
  f = line.chomp.split(&amp;#039; &amp;#039;) &lt;br /&gt;
  if !header then &lt;br /&gt;
    header = f &lt;br /&gt;
    TIME = f.rindex(&amp;#039;TIME&amp;#039;)&lt;br /&gt;
    CMD = f.rindex(&amp;#039;CMD&amp;#039;) || f.rindex(&amp;#039;COMMAND&amp;#039;)&lt;br /&gt;
  else &lt;br /&gt;
    time = f[TIME].split(&amp;#039;:&amp;#039;)&lt;br /&gt;
    seconds = time[0].to_i * 60 + time[1].to_i&lt;br /&gt;
    cmd = f[CMD]&lt;br /&gt;
    procs[cmd] += seconds&lt;br /&gt;
  end &lt;br /&gt;
end &lt;br /&gt;
 &lt;br /&gt;
sum = 0.0&lt;br /&gt;
procs.each { |k,v| sum += v }&lt;br /&gt;
sorted = procs.sort { |a,b| b[1]&amp;lt;=&amp;gt;a[1] }&lt;br /&gt;
sorted.each do |k|&lt;br /&gt;
  puts sprintf(&amp;quot;%-10s %5.2f%%&amp;quot;, k[0], (k[1] / sum) * 100.0)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s a sample of it&amp;#039;s usage:&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ps -A -o user,time,nlwp,fname | ./sumcputime.rb | head&lt;br /&gt;
java       27.19%&lt;br /&gt;
dataserv   20.10%&lt;br /&gt;
Xvnc        7.21%&lt;br /&gt;
view_ser    4.06%&lt;br /&gt;
backupse    3.86%&lt;br /&gt;
httpd       3.64%&lt;br /&gt;
nscd        2.81%&lt;br /&gt;
omniName    2.38%&lt;br /&gt;
se.sparc    2.34%&lt;br /&gt;
compute_    2.10%&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Ruby]]&lt;br /&gt;
[[Category:Solaris]]&lt;/div&gt;</summary>
		<author><name>Egge</name></author>
	</entry>
</feed>