|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 2445 (0x98d)
Types: TextFile
Names: »uptime.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec8/uptime/uptime.c«
/*
* uptime.c -- Print how long the system has been up
* System V Implmenentation
*
* (sjm@dayton) Steven McDowall
*
* cc -O -o uptime uptime.c
* chown root uptime
* chmod u+s uptime So we can read /dev/kmem
*/
# include <sys/types.h> /* system types */
# include <sys/sysinfo.h> /* sysinfo structure */
# include <sys/param.h> /* for HZ */
# include <stdio.h>
# include <nlist.h>
# include <fcntl.h>
# include <time.h>
#define MINUTES 60
#define HOURS (MINUTES * 60)
#define DAYS (HOURS * 24)
# define SYSTEM "/unix"
# define KMEM "/dev/kmem"
struct nlist nl[] = {
# define NL_SYSINFO 0
{ "sysinfo" }, /* 0 */
# define NL_LBOLT 1
{ "lbolt" }, /* 1 */
{ 0 }
};
int memfd;
char *system = SYSTEM;
char *kmem = KMEM;
char *argv0;
main(argc, argv)
int argc;
char *argv[];
{
time_t boothz, uptime;
void ptime();
argv0 = argv[0];
init_nlist(); /* get name values, open kmem */
/*
Now read kmem to get the boot time
*/
l_lseek(memfd, (long)nl[NL_LBOLT].n_value, 0);
r_read(memfd, (char *)&boothz, sizeof( boothz ) );
uptime = (boothz / HZ);
ptime(uptime);
} /* main */
\f
init_nlist()
{
nlist(system, nl); /* get system values */
if(nl[NL_SYSINFO].n_value == 0)
{
fprintf(stderr, "%s: can't find sysinf structure\n", argv0);
exit(1);
} /* no value */
if ((memfd = open(kmem, O_RDONLY)) < 0)
{
fprintf(stderr, "%s: no mem\n", argv0);
exit(1);
} /* could not open kmem */
} /* init_nlist */
/* lseek with error checking */
l_lseek(fd, offset, whence)
int fd, whence;
long offset;
{
if (lseek(fd, offset, whence) == -1)
{
fprintf(stderr, "%s: error on lseek\n", argv0);
exit(1);
}
}
/* read with error checking */
r_read (fd, buf, nbytes)
int fd, nbytes;
char *buf;
{
if (read(fd, buf, nbytes) != nbytes)
{
fprintf(stderr, "%s: error on read\n", argv0);
exit(1);
}
}
\f
/*
Print the time in a nice format
*/
void ptime(secs)
time_t secs;
{
short days, hours, minutes;
secs -= (days = secs / DAYS) * DAYS;
secs -= (hours = secs / HOURS) * HOURS;
secs -= (minutes = secs / MINUTES) * MINUTES;
printf("The system has been up for ");
if (days != 0)
printf("%d %s ", days, (days == 1 ? "day" : "days"));
if (hours != 0)
printf("%d %s ", hours, (hours == 1 ? "hour" : "hours"));
if (minutes != 0)
printf("%d %s ", minutes, (minutes == 1 ? "minute" : "minutes"));
printf("and %d %s.\n", secs, (secs == 1 ? "second" : "seconds"));
}