Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/rc/what

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


#!/bin/rc

@{ for ( file in /proc/[0-9]*/status){
	cat $file >[2] /dev/null && echo ''
}} |
	awk '
		BEGIN{
			ofs = FS;
			FS="|";
			while (getline < "/adm/keys.who")
				really[$1] = $3;
			while (getline < "/adm/netkeys.who")
				really[$1] = $3;
			FS=ofs;

			"date -n" | getline now;
		}

		{
			nproc[$2]++;
			utime[$2] += $4;
			stime[$2] += $5;
			if ($6 == "" || $6 > rtime[$2])
				rtime[$2] = $6;
			if($2 != prev)
				memsz[$2] += $10;
			prev = $2;
		}
		END {
			for (u in nproc)
				printf("%-12s %3d %10s %10s %6.1fMb  %8s  %s\n",
					u,
					nproc[u],
					s2ms(utime[u]/1000),
					s2ms(stime[u]/1000),
					memsz[u]/1024.0,
					when(rtime[u]/1000),
					really[u]);
		}
		function s2ms(n){
			return sprintf("%d:%02d", n/60, n%60);
		}
		function when(s,		d, h, m){
			d = int(s/86400); s -= d*86400;
			h = int(s/3600);  s -= h*3600;
			m = int(s/60);   s -= m*60;
			if (d != 0)
				return sprintf("%dd", d);
			else
				return sprintf("%dh", h);
		}
	' 

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].