display.c (41943) | display.c (42447) |
---|---|
1/* 2 * Top users/processes display for Unix 3 * Version 3 4 * 5 * This program may be freely redistributed, 6 * but this entire comment MUST remain intact. 7 * 8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University --- 16 unchanged lines hidden (view full) --- 25 * *_procstates, *_cpustates, *_memory, *_message, *_header, 26 * *_process, u_endscreen. 27 */ 28 29#include "os.h" 30#include <ctype.h> 31#include <time.h> 32#include <sys/time.h> | 1/* 2 * Top users/processes display for Unix 3 * Version 3 4 * 5 * This program may be freely redistributed, 6 * but this entire comment MUST remain intact. 7 * 8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University --- 16 unchanged lines hidden (view full) --- 25 * *_procstates, *_cpustates, *_memory, *_message, *_header, 26 * *_process, u_endscreen. 27 */ 28 29#include "os.h" 30#include <ctype.h> 31#include <time.h> 32#include <sys/time.h> |
33#include <sys/types.h> 34#include <sys/sysctl.h> | |
35 36#include "screen.h" /* interface to screen package */ 37#include "layout.h" /* defines for screen position layout */ 38#include "display.h" 39#include "top.h" 40#include "top.local.h" 41#include "boolean.h" 42#include "machine.h" /* we should eliminate this!!! */ --- 195 unchanged lines hidden (view full) --- 238 for (i = 0; i < 3; i++) 239 { 240 printf("%s%5.2f", 241 i == 0 ? "" : ", ", 242 avenrun[i]); 243 } 244} 245 | 33 34#include "screen.h" /* interface to screen package */ 35#include "layout.h" /* defines for screen position layout */ 36#include "display.h" 37#include "top.h" 38#include "top.local.h" 39#include "boolean.h" 40#include "machine.h" /* we should eliminate this!!! */ --- 195 unchanged lines hidden (view full) --- 236 for (i = 0; i < 3; i++) 237 { 238 printf("%s%5.2f", 239 i == 0 ? "" : ", ", 240 avenrun[i]); 241 } 242} 243 |
246struct timeval boottime; 247time_t now; 248time_t uptime; 249 | |
250i_timeofday(tod) 251 252time_t *tod; 253 254{ | 244i_timeofday(tod) 245 246time_t *tod; 247 248{ |
255 int days, hrs, i, mins, secs; 256 int mib[2]; 257 size_t size; 258 259 (void)time(&now); 260 261 /* 262 * Print how long system has been up. 263 * (Found by looking getting "boottime" from the kernel) 264 */ 265 mib[0] = CTL_KERN; 266 mib[1] = KERN_BOOTTIME; 267 size = sizeof(boottime); 268 if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && 269 boottime.tv_sec != 0) { 270 uptime = now - boottime.tv_sec; 271 uptime += 30; 272 days = uptime / 86400; 273 uptime %= 86400; 274 hrs = uptime / 3600; 275 uptime %= 3600; 276 mins = uptime / 60; 277 secs = uptime % 60; 278 279 if (smart_terminal) 280 { 281 Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0); 282 } 283 else 284 { 285 fputs(" ", stdout); 286 } 287 288 printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs); 289 } 290 | |
291 /* 292 * Display the current time. 293 * "ctime" always returns a string that looks like this: 294 * 295 * Sun Sep 16 01:03:52 1973 296 * 012345678901234567890123 297 * 1 2 298 * --- 907 unchanged lines hidden (view full) --- 1206 if (!isprint(ch)) 1207 { 1208 *ptr = '?'; 1209 } 1210 ptr++; 1211 } 1212 return(str); 1213} | 249 /* 250 * Display the current time. 251 * "ctime" always returns a string that looks like this: 252 * 253 * Sun Sep 16 01:03:52 1973 254 * 012345678901234567890123 255 * 1 2 256 * --- 907 unchanged lines hidden (view full) --- 1164 if (!isprint(ch)) 1165 { 1166 *ptr = '?'; 1167 } 1168 ptr++; 1169 } 1170 return(str); 1171} |
1172 1173i_uptime(bt, tod) 1174 1175struct timeval* bt; 1176time_t *tod; 1177 1178{ 1179 time_t uptime; 1180 int days, hrs, mins, secs; 1181 1182 if (bt->tv_sec != -1) { 1183 uptime = *tod - bt->tv_sec; 1184 uptime += 30; 1185 days = uptime / 86400; 1186 uptime %= 86400; 1187 hrs = uptime / 3600; 1188 uptime %= 3600; 1189 mins = uptime / 60; 1190 secs = uptime % 60; 1191 1192 /* 1193 * Display the uptime. 1194 */ 1195 1196 if (smart_terminal) 1197 { 1198 Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0); 1199 } 1200 else 1201 { 1202 fputs(" ", stdout); 1203 } 1204 printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs); 1205 } 1206} |
|