🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99038

loadst for system V & RS/6000

#99038
From: Doug Stailey
Date: Fri, 30 Nov 1990 01:20
174 lines
3925 bytes
/* Ken Stailey's loadst.c for USG systems including the RS/6000 */

#include <stdio.h>
#include <fcntl.h>
#include <nlist.h>
#include <sys/sysinfo.h>

#ifndef _AIX
# include <ctype.h>
# define TRUE 1
# define FALSE 0
#endif

char *prog_name;

main(argc, argv)
int argc;
char *argv[];
{
	int km;
#ifdef _AIX
	struct nlist nl;
#else
	struct nlist nl[2];
#endif
	struct sysinfo si;
	long old_runque = 0;
	int sleep_time = 1;
	time_t now;
	char temp_time[27], the_time[9], *p;
	int newline = TRUE;
	int repeat = 0;

	prog_name = argv[0];

	switch (argc)
	{	case 1:
			/* no args is fine */
		break;

		case 2:
			if (strcmp(argv[1], "-n") == 0)
			{	newline = FALSE;
				break;
			}
			sleep_time = must_be_number(argv[1]);
			repeat = 1;
		break;

		case 3:
			if (strcmp(argv[1], "-n") == 0)
				newline = FALSE;
			else
				usage();

			sleep_time = must_be_number(argv[2]);
			repeat = 1;
		break;

		default:
			usage();
	}

	/* grab "sysinfo structure out of the kernel */

	if ((km = open("/dev/kmem", O_RDONLY)) < 1)
	{	perror("open /dev/kmem failed");
		exit(-1);
	}

#ifdef _AIX
	nl.n_name = "sysinfo";
#else
	nl[0].n_name = "sysinfo";
	nl[1].n_name = "";
#endif

	do
	{
#ifdef _AIX
		if (knlist(&nl, 1, sizeof(nl)) < 0)
		{	perror("knlist for sysinfo failed");
			exit(-1);
		}

		if (lseek(km, nl.n_value, SEEK_SET) < 0)
		{	perror("lseek on kmem failed");
			exit(-1);
		}
#else
		if (nlist("/unix", nl) < 0)
		{	perror("nlist of /unix for sysinfo failed");
			exit(-1);
		}

		if (lseek(km, nl[0].n_value, SEEK_SET) != nl[0].n_value)
		{	perror("lseek on kmem failed");
			exit(-1);
		}
#endif

		if (read(km, &si, sizeof(si)) < sizeof(si))
		{	perror("read of sysinfo from kmem failed");
			exit(-1);
		}

	/* generate HH:MMam/pm timestamp */

		time(&now);
		strcpy(temp_time, ctime(&now));
		p = temp_time + 11;
		strncpy(the_time, p, 5);
		strncpy(temp_time, the_time, 2);
		now = atol(temp_time);
		if (now > 12)
		{	now -= 12;
			strcpy(temp_time, &the_time[2]);
			sprintf(the_time, "%02d%s", now, temp_time);
			the_time[5] = 'p';
		}
		else
			the_time[5] = 'a';
		the_time[6] = 'm';
		the_time[7] = '\0';

	/* display the time and load */

		if (old_runque != 0)
		{	printf("%s %4.2f",
				the_time,
				((double)(si.runque - old_runque)
				/ (double)(sleep_time))
				- (double)(1.0));
			if (newline)
				printf("\n");
			fflush(stdout);
		}
		else
		{	printf("%s %*.2f", the_time, 0.0);
			if (newline)
				printf("\n");
			fflush(stdout);
		}

		old_runque = si.runque; /* for delta of ticks */

		if (repeat)
			sleep(sleep_time);
	} while (repeat);
}

usage()
{
	fprintf(stderr, "usage: %s [seconds between updates (default = 1)]\n",
		prog_name);
	exit(-1);
}

must_be_number(numeral)
char *numeral;
{
	int i, temp;

	for (i = 0; numeral[i] && i < 7; i++)
	{	if (!isdigit(numeral[i]))
			usage();
	}

	sscanf(numeral, "%i", &temp);
	return temp;
}
-- 
disclaimer: This message is sold by weight, not volume.  Contents may have
	    settled during shipment.
Technical Details
Message-ID: <1990Nov30.012014.8085@mintaka.lcs.mit.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!GNU.AI.MIT.EDU!dstailey
References: <LJZ.90Nov21082354@benji.sisyphus.shearson.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,a3e9b9c99ab3ee3e
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-11-29 17:20:14 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!GNU.AI.MIT.EDU!dstailey
From: dstailey@GNU.AI.MIT.EDU (Doug Stailey)
Newsgroups: gnu.emacs.bug
Subject: loadst for system V & RS/6000
Summary: here's a loadst that uses sysinfo instead of avenrun
Message-ID: <1990Nov30.012014.8085@mintaka.lcs.mit.edu>
Date: 30 Nov 90 01:20:14 GMT
References: <LJZ.90Nov21082354@benji.sisyphus.shearson.com>
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: MIT Laboratory for Computer Science
Lines: 174
Approved: bug-gnu-emacs@prep.ai.mit.edu
Posted: Fri Nov 30 02:20:14 1990