Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/scripts/atop

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/awk -f

BEGIN {
	nam=1; owner=2; status=3; usr=4; sys=5; real=6; cusr=7; csys=8; creal=9; siz=10

	while ( 1 ) {
		lps = "ls -dp /proc/* | tr '\n' ' >[2] /dev/null '"
		# Due to races in /proc reading, procs can disapear under ls's feet, should
		# send ls's stderr to /dev/null
		lps | getline ps; close lps
		split(ps, psa)
		for ( p in psa ) {
			pid = psa[p]
			vals = ""
			gval = "/proc/"pid"/status"
			getline vals <gval; close gval
			if ( vals ~ "^$" ) continue # Process is gone
			split(vals, val)
			new[pid] = val[usr] + val[sys]
			delta[pid] = new[pid] - old[pid]
			inf[pid] = vals
		}
		delete old
		srt = "sort -r -n +2"
		for ( pid in delta ) {
			if ( delta[pid] > 0 ) {
				split(inf[pid], i)
				ut = i[usr]/1000
				st = i[sys]/1000
				s = sprintf("%-10s %8s %6s %4ld:%.2ld %3ld:%.2ld %7ldK %-8s %s",
					i[owner], pid, delta[pid], ut/60, ut%60, st/60, st%60,
					i[siz], i[status], i[nam])
				print s|srt
			}
			old[pid] = new[pid]
		}
		delete new; delete delta; delete inf
		close(srt)
		print "----------------------------------------------------------------"
		system("sleep 1")
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.