Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/scripts/watchfd

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


#!/bin/rc

fn watch {
	pid=$1
	fd=$2
	file=`{cat /proc/$pid/fd | awk '$1=='^$fd^' {print $NF}'}
	title=$3
	sz=`{ls -l $file | awk '{print $6}'}
	{
		while(test -f /proc/$pid/fd) {
			cat /proc/$pid/fd | awk '$1=='^$fd^' {printf("%d '^$sz^'\n", $6);}'
			sleep 1;
		}
	} | bargraph $title
}

switch($#*) {
case 1
	for (i in `{ps|awk '$2=="'^$1^'" || $7=="'^$1^'" {print $2}'})
		cat /proc/$i/fd | awk 'NF==7{printf("watchfd '^$i^' %d %s\n", $1, $7);}'
case 2
	pid=$1
	fd=$2
	file=`{cat /proc/$pid/fd | awk '$1=='^$fd^' {print $NF}'}
	watch $pid $fd $file
case 3
	watch $1 $2 $3
case *
	echo 'usage: watchfd proc [fd] [title]' >[1=2]
	exit usage
}

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].