top.c revision 81187
1char *copyright = 2 "Copyright (c) 1984 through 1996, William LeFebvre"; 3 4/* 5 * Top users/processes display for Unix 6 * Version 3 7 * 8 * This program may be freely redistributed, 9 * but this entire comment MUST remain intact. 10 * 11 * Copyright (c) 1984, 1989, William LeFebvre, Rice University 12 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University 13 * 14 * $FreeBSD: head/contrib/top/top.c 81187 2001-08-06 03:19:22Z kris $ 15 */ 16 17/* 18 * See the file "Changes" for information on version-to-version changes. 19 */ 20 21/* 22 * This file contains "main" and other high-level routines. 23 */ 24 25/* 26 * The following preprocessor variables, when defined, are used to 27 * distinguish between different Unix implementations: 28 * 29 * SIGHOLD - use SVR4 sighold function when defined 30 * SIGRELSE - use SVR4 sigrelse function when defined 31 * FD_SET - macros FD_SET and FD_ZERO are used when defined 32 */ 33 34#include "os.h" 35#include <signal.h> 36#include <setjmp.h> 37#include <ctype.h> 38#include <sys/time.h> 39 40/* includes specific to top */ 41#include "display.h" /* interface to display package */ 42#include "screen.h" /* interface to screen package */ 43#include "top.h" 44#include "top.local.h" 45#include "boolean.h" 46#include "machine.h" 47#include "utils.h" 48 49/* Size of the stdio buffer given to stdout */ 50#define Buffersize 2048 51 52/* The buffer that stdio will use */ 53char stdoutbuf[Buffersize]; 54 55/* build Signal masks */ 56#define Smask(s) (1 << ((s) - 1)) 57 58/* for system errors */ 59extern int errno; 60 61/* for getopt: */ 62extern int optind; 63extern char *optarg; 64 65/* imported from screen.c */ 66extern int overstrike; 67 68/* signal handling routines */ 69sigret_t leave(); 70sigret_t onalrm(); 71sigret_t tstop(); 72#ifdef SIGWINCH 73sigret_t winch(); 74#endif 75 76volatile sig_atomic_t leaveflag; 77volatile sig_atomic_t tstopflag; 78volatile sig_atomic_t winchflag; 79 80/* internal routines */ 81void quit(); 82 83/* values which need to be accessed by signal handlers */ 84static int max_topn; /* maximum displayable processes */ 85 86/* miscellaneous things */ 87char *myname = "top"; 88jmp_buf jmp_int; 89 90/* routines that don't return int */ 91 92char *username(); 93char *ctime(); 94char *kill_procs(); 95char *renice_procs(); 96 97#ifdef ORDER 98extern int (*proc_compares[])(); 99#else 100extern int proc_compare(); 101#endif 102time_t time(); 103 104caddr_t get_process_info(); 105 106/* different routines for displaying the user's identification */ 107/* (values assigned to get_userid) */ 108char *username(); 109char *itoa7(); 110 111/* display routines that need to be predeclared */ 112int i_loadave(); 113int u_loadave(); 114int i_procstates(); 115int u_procstates(); 116int i_cpustates(); 117int u_cpustates(); 118int i_memory(); 119int u_memory(); 120int i_swap(); 121int u_swap(); 122int i_message(); 123int u_message(); 124int i_header(); 125int u_header(); 126int i_process(); 127int u_process(); 128 129/* pointers to display routines */ 130int (*d_loadave)() = i_loadave; 131int (*d_procstates)() = i_procstates; 132int (*d_cpustates)() = i_cpustates; 133int (*d_memory)() = i_memory; 134int (*d_swap)() = i_swap; 135int (*d_message)() = i_message; 136int (*d_header)() = i_header; 137int (*d_process)() = i_process; 138 139 140main(argc, argv) 141 142int argc; 143char *argv[]; 144 145{ 146 register int i; 147 register int active_procs; 148 register int change; 149 150 struct system_info system_info; 151 struct statics statics; 152 caddr_t processes; 153 154 static char tempbuf1[50]; 155 static char tempbuf2[50]; 156 int old_sigmask; /* only used for BSD-style signals */ 157 int topn = Default_TOPN; 158 int delay = Default_DELAY; 159 int displays = 0; /* indicates unspecified */ 160 time_t curr_time; 161 char *(*get_userid)() = username; 162 char *uname_field = "USERNAME"; 163 char *header_text; 164 char *env_top; 165 char **preset_argv; 166 int preset_argc = 0; 167 char **av; 168 int ac; 169 char dostates = No; 170 char do_unames = Yes; 171 char interactive = Maybe; 172 char warnings = 0; 173#if Default_TOPN == Infinity 174 char topn_specified = No; 175#endif 176 char ch; 177 char *iptr; 178 char no_command = 1; 179 struct timeval timeout; 180 struct process_select ps; 181#ifdef ORDER 182 char *order_name = NULL; 183 int order_index = 0; 184#endif 185#ifndef FD_SET 186 /* FD_SET and friends are not present: fake it */ 187 typedef int fd_set; 188#define FD_ZERO(x) (*(x) = 0) 189#define FD_SET(f, x) (*(x) = f) 190#endif 191 fd_set readfds; 192 193#ifdef ORDER 194 static char command_chars[] = "\f qh?en#sdkriIuto"; 195#else 196 static char command_chars[] = "\f qh?en#sdkriIut"; 197#endif 198/* these defines enumerate the "strchr"s of the commands in command_chars */ 199#define CMD_redraw 0 200#define CMD_update 1 201#define CMD_quit 2 202#define CMD_help1 3 203#define CMD_help2 4 204#define CMD_OSLIMIT 4 /* terminals with OS can only handle commands */ 205#define CMD_errors 5 /* less than or equal to CMD_OSLIMIT */ 206#define CMD_number1 6 207#define CMD_number2 7 208#define CMD_delay 8 209#define CMD_displays 9 210#define CMD_kill 10 211#define CMD_renice 11 212#define CMD_idletog 12 213#define CMD_idletog2 13 214#define CMD_user 14 215#define CMD_selftog 15 216#ifdef ORDER 217#define CMD_order 16 218#endif 219 220 /* set the buffer for stdout */ 221#ifdef DEBUG 222 setbuffer(stdout, NULL, 0); 223#else 224 setbuffer(stdout, stdoutbuf, Buffersize); 225#endif 226 227 /* get our name */ 228 if (argc > 0) 229 { 230 if ((myname = strrchr(argv[0], '/')) == 0) 231 { 232 myname = argv[0]; 233 } 234 else 235 { 236 myname++; 237 } 238 } 239 240 /* initialize some selection options */ 241 ps.idle = Yes; 242 ps.self = -1; 243 ps.system = No; 244 ps.uid = -1; 245 ps.command = NULL; 246 247 /* get preset options from the environment */ 248 if ((env_top = getenv("TOP")) != NULL) 249 { 250 av = preset_argv = argparse(env_top, &preset_argc); 251 ac = preset_argc; 252 253 /* set the dummy argument to an explanatory message, in case 254 getopt encounters a bad argument */ 255 preset_argv[0] = "while processing environment"; 256 } 257 258 /* process options */ 259 do { 260 /* if we're done doing the presets, then process the real arguments */ 261 if (preset_argc == 0) 262 { 263 ac = argc; 264 av = argv; 265 266 /* this should keep getopt happy... */ 267 optind = 1; 268 } 269 270 while ((i = getopt(ac, av, "SIbinqus:d:U:o:t")) != EOF) 271 { 272 switch(i) 273 { 274 case 'u': /* toggle uid/username display */ 275 do_unames = !do_unames; 276 break; 277 278 case 'U': /* display only username's processes */ 279 if ((ps.uid = userid(optarg)) == -1) 280 { 281 fprintf(stderr, "%s: unknown user\n", optarg); 282 exit(1); 283 } 284 break; 285 286 case 'S': /* show system processes */ 287 ps.system = !ps.system; 288 break; 289 290 case 'I': /* show idle processes */ 291 ps.idle = !ps.idle; 292 break; 293 294 case 'i': /* go interactive regardless */ 295 interactive = Yes; 296 break; 297 298 case 'n': /* batch, or non-interactive */ 299 case 'b': 300 interactive = No; 301 break; 302 303 case 'd': /* number of displays to show */ 304 if ((i = atoiwi(optarg)) == Invalid || i == 0) 305 { 306 fprintf(stderr, 307 "%s: warning: display count should be positive -- option ignored\n", 308 myname); 309 warnings++; 310 } 311 else 312 { 313 displays = i; 314 } 315 break; 316 317 case 's': 318 if ((delay = atoi(optarg)) < 0) 319 { 320 fprintf(stderr, 321 "%s: warning: seconds delay should be non-negative -- using default\n", 322 myname); 323 delay = Default_DELAY; 324 warnings++; 325 } 326 break; 327 328 case 'q': /* be quick about it */ 329 /* only allow this if user is really root */ 330 if (getuid() == 0) 331 { 332 /* be very un-nice! */ 333 (void) nice(-20); 334 } 335 else 336 { 337 fprintf(stderr, 338 "%s: warning: `-q' option can only be used by root\n", 339 myname); 340 warnings++; 341 } 342 break; 343 344 case 'o': /* select sort order */ 345#ifdef ORDER 346 order_name = optarg; 347#else 348 fprintf(stderr, 349 "%s: this platform does not support arbitrary ordering. Sorry.\n", 350 myname); 351 warnings++; 352#endif 353 break; 354 355 case 't': 356 ps.self = (ps.self == -1) ? getpid() : -1; 357 break; 358 359 default: 360 fprintf(stderr, "\ 361Top version %s\n\ 362Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", 363 version_string(), myname); 364 exit(1); 365 } 366 } 367 368 /* get count of top processes to display (if any) */ 369 if (optind < ac) 370 { 371 if ((topn = atoiwi(av[optind])) == Invalid) 372 { 373 fprintf(stderr, 374 "%s: warning: process display count should be non-negative -- using default\n", 375 myname); 376 warnings++; 377 } 378#if Default_TOPN == Infinity 379 else 380 { 381 topn_specified = Yes; 382 } 383#endif 384 } 385 386 /* tricky: remember old value of preset_argc & set preset_argc = 0 */ 387 i = preset_argc; 388 preset_argc = 0; 389 390 /* repeat only if we really did the preset arguments */ 391 } while (i != 0); 392 393 /* set constants for username/uid display correctly */ 394 if (!do_unames) 395 { 396 uname_field = " UID "; 397 get_userid = itoa7; 398 } 399 400 /* initialize the kernel memory interface */ 401 if (machine_init(&statics) == -1) 402 { 403 exit(1); 404 } 405 406#ifdef ORDER 407 /* determine sorting order index, if necessary */ 408 if (order_name != NULL) 409 { 410 if ((order_index = string_index(order_name, statics.order_names)) == -1) 411 { 412 char **pp; 413 414 fprintf(stderr, "%s: '%s' is not a recognized sorting order.\n", 415 myname, order_name); 416 fprintf(stderr, "\tTry one of these:"); 417 pp = statics.order_names; 418 while (*pp != NULL) 419 { 420 fprintf(stderr, " %s", *pp++); 421 } 422 fputc('\n', stderr); 423 exit(1); 424 } 425 } 426#endif 427 428#ifdef no_initialization_needed 429 /* initialize the hashing stuff */ 430 if (do_unames) 431 { 432 init_hash(); 433 } 434#endif 435 436 /* initialize termcap */ 437 init_termcap(interactive); 438 439 /* get the string to use for the process area header */ 440 header_text = format_header(uname_field); 441 442 /* initialize display interface */ 443 if ((max_topn = display_init(&statics)) == -1) 444 { 445 fprintf(stderr, "%s: can't allocate sufficient memory\n", myname); 446 exit(4); 447 } 448 449 /* print warning if user requested more processes than we can display */ 450 if (topn > max_topn) 451 { 452 fprintf(stderr, 453 "%s: warning: this terminal can only display %d processes.\n", 454 myname, max_topn); 455 warnings++; 456 } 457 458 /* adjust for topn == Infinity */ 459 if (topn == Infinity) 460 { 461 /* 462 * For smart terminals, infinity really means everything that can 463 * be displayed, or Largest. 464 * On dumb terminals, infinity means every process in the system! 465 * We only really want to do that if it was explicitly specified. 466 * This is always the case when "Default_TOPN != Infinity". But if 467 * topn wasn't explicitly specified and we are on a dumb terminal 468 * and the default is Infinity, then (and only then) we use 469 * "Nominal_TOPN" instead. 470 */ 471#if Default_TOPN == Infinity 472 topn = smart_terminal ? Largest : 473 (topn_specified ? Largest : Nominal_TOPN); 474#else 475 topn = Largest; 476#endif 477 } 478 479 /* set header display accordingly */ 480 display_header(topn > 0); 481 482 /* determine interactive state */ 483 if (interactive == Maybe) 484 { 485 interactive = smart_terminal; 486 } 487 488 /* if # of displays not specified, fill it in */ 489 if (displays == 0) 490 { 491 displays = smart_terminal ? Infinity : 1; 492 } 493 494 /* hold interrupt signals while setting up the screen and the handlers */ 495#ifdef SIGHOLD 496 sighold(SIGINT); 497 sighold(SIGQUIT); 498 sighold(SIGTSTP); 499#else 500 old_sigmask = sigblock(Smask(SIGINT) | Smask(SIGQUIT) | Smask(SIGTSTP)); 501#endif 502 init_screen(); 503 (void) signal(SIGINT, leave); 504 (void) signal(SIGQUIT, leave); 505 (void) signal(SIGTSTP, tstop); 506#ifdef SIGWINCH 507 (void) signal(SIGWINCH, winch); 508#endif 509#ifdef SIGRELSE 510 sigrelse(SIGINT); 511 sigrelse(SIGQUIT); 512 sigrelse(SIGTSTP); 513#else 514 (void) sigsetmask(old_sigmask); 515#endif 516 if (warnings) 517 { 518 fputs("....", stderr); 519 fflush(stderr); /* why must I do this? */ 520 sleep((unsigned)(3 * warnings)); 521 fputc('\n', stderr); 522 } 523 524restart: 525 526 /* 527 * main loop -- repeat while display count is positive or while it 528 * indicates infinity (by being -1) 529 */ 530 531 while ((displays == -1) || (displays-- > 0)) 532 { 533 /* get the current stats */ 534 get_system_info(&system_info); 535 536 /* get the current set of processes */ 537 processes = 538 get_process_info(&system_info, 539 &ps, 540#ifdef ORDER 541 proc_compares[order_index]); 542#else 543 proc_compare); 544#endif 545 546 /* display the load averages */ 547 (*d_loadave)(system_info.last_pid, 548 system_info.load_avg); 549 550 /* display the current time */ 551 /* this method of getting the time SHOULD be fairly portable */ 552 time(&curr_time); 553 i_uptime(&system_info.boottime, &curr_time); 554 i_timeofday(&curr_time); 555 556 /* display process state breakdown */ 557 (*d_procstates)(system_info.p_total, 558 system_info.procstates); 559 560 /* display the cpu state percentage breakdown */ 561 if (dostates) /* but not the first time */ 562 { 563 (*d_cpustates)(system_info.cpustates); 564 } 565 else 566 { 567 /* we'll do it next time */ 568 if (smart_terminal) 569 { 570 z_cpustates(); 571 } 572 else 573 { 574 putchar('\n'); 575 } 576 dostates = Yes; 577 } 578 579 /* display memory stats */ 580 (*d_memory)(system_info.memory); 581 582 /* display swap stats */ 583 (*d_swap)(system_info.swap); 584 585 /* handle message area */ 586 (*d_message)(); 587 588 /* update the header area */ 589 (*d_header)(header_text); 590 591 if (topn > 0) 592 { 593 /* determine number of processes to actually display */ 594 /* this number will be the smallest of: active processes, 595 number user requested, number current screen accomodates */ 596 active_procs = system_info.p_active; 597 if (active_procs > topn) 598 { 599 active_procs = topn; 600 } 601 if (active_procs > max_topn) 602 { 603 active_procs = max_topn; 604 } 605 606 /* now show the top "n" processes. */ 607 for (i = 0; i < active_procs; i++) 608 { 609 (*d_process)(i, format_next_process(processes, get_userid)); 610 } 611 } 612 else 613 { 614 i = 0; 615 } 616 617 /* do end-screen processing */ 618 u_endscreen(i); 619 620 /* now, flush the output buffer */ 621 fflush(stdout); 622 623 /* only do the rest if we have more displays to show */ 624 if (displays) 625 { 626 /* switch out for new display on smart terminals */ 627 if (smart_terminal) 628 { 629 if (overstrike) 630 { 631 reset_display(); 632 } 633 else 634 { 635 d_loadave = u_loadave; 636 d_procstates = u_procstates; 637 d_cpustates = u_cpustates; 638 d_memory = u_memory; 639 d_swap = u_swap; 640 d_message = u_message; 641 d_header = u_header; 642 d_process = u_process; 643 } 644 } 645 646 no_command = Yes; 647 if (!interactive) 648 { 649 /* set up alarm */ 650 (void) signal(SIGALRM, onalrm); 651 (void) alarm((unsigned)delay); 652 653 /* wait for the rest of it .... */ 654 pause(); 655 } 656 else while (no_command) 657 { 658 /* assume valid command unless told otherwise */ 659 no_command = No; 660 661 /* set up arguments for select with timeout */ 662 FD_ZERO(&readfds); 663 FD_SET(1, &readfds); /* for standard input */ 664 timeout.tv_sec = delay; 665 timeout.tv_usec = 0; 666 667 if (leaveflag) { 668 end_screen(); 669 exit(0); 670 } 671 672 if (tstopflag) { 673 /* move to the lower left */ 674 end_screen(); 675 fflush(stdout); 676 677 /* default the signal handler action */ 678 (void) signal(SIGTSTP, SIG_DFL); 679 680 /* unblock the signal and send ourselves one */ 681#ifdef SIGRELSE 682 sigrelse(SIGTSTP); 683#else 684 (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1))); 685#endif 686 (void) kill(0, SIGTSTP); 687 688 /* reset the signal handler */ 689 (void) signal(SIGTSTP, tstop); 690 691 /* reinit screen */ 692 reinit_screen(); 693 reset_display(); 694 tstopflag = 0; 695 goto restart; 696 } 697 698 if (winchflag) { 699 /* reascertain the screen dimensions */ 700 get_screensize(); 701 702 /* tell display to resize */ 703 max_topn = display_resize(); 704 705 /* reset the signal handler */ 706 (void) signal(SIGWINCH, winch); 707 708 reset_display(); 709 winchflag = 0; 710 goto restart; 711 } 712 713 /* wait for either input or the end of the delay period */ 714 if (select(32, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout) > 0) 715 { 716 int newval; 717 char *errmsg; 718 719 /* something to read -- clear the message area first */ 720 clear_message(); 721 722 /* now read it and convert to command strchr */ 723 /* (use "change" as a temporary to hold strchr) */ 724 (void) read(0, &ch, 1); 725 if ((iptr = strchr(command_chars, ch)) == NULL) 726 { 727 if (ch != '\r' && ch != '\n') 728 { 729 /* illegal command */ 730 new_message(MT_standout, " Command not understood"); 731 } 732 putchar('\r'); 733 no_command = Yes; 734 } 735 else 736 { 737 change = iptr - command_chars; 738 if (overstrike && change > CMD_OSLIMIT) 739 { 740 /* error */ 741 new_message(MT_standout, 742 " Command cannot be handled by this terminal"); 743 putchar('\r'); 744 no_command = Yes; 745 } 746 else switch(change) 747 { 748 case CMD_redraw: /* redraw screen */ 749 reset_display(); 750 break; 751 752 case CMD_update: /* merely update display */ 753 /* is the load average high? */ 754 if (system_info.load_avg[0] > LoadMax) 755 { 756 /* yes, go home for visual feedback */ 757 go_home(); 758 fflush(stdout); 759 } 760 break; 761 762 case CMD_quit: /* quit */ 763 quit(0); 764 /*NOTREACHED*/ 765 break; 766 767 case CMD_help1: /* help */ 768 case CMD_help2: 769 reset_display(); 770 clear(); 771 show_help(); 772 standout("Hit any key to continue: "); 773 fflush(stdout); 774 (void) read(0, &ch, 1); 775 break; 776 777 case CMD_errors: /* show errors */ 778 if (error_count() == 0) 779 { 780 new_message(MT_standout, 781 " Currently no errors to report."); 782 putchar('\r'); 783 no_command = Yes; 784 } 785 else 786 { 787 reset_display(); 788 clear(); 789 show_errors(); 790 standout("Hit any key to continue: "); 791 fflush(stdout); 792 (void) read(0, &ch, 1); 793 } 794 break; 795 796 case CMD_number1: /* new number */ 797 case CMD_number2: 798 new_message(MT_standout, 799 "Number of processes to show: "); 800 newval = readline(tempbuf1, 8, Yes); 801 if (newval > -1) 802 { 803 if (newval > max_topn) 804 { 805 new_message(MT_standout | MT_delayed, 806 " This terminal can only display %d processes.", 807 max_topn); 808 putchar('\r'); 809 } 810 811 if (newval == 0) 812 { 813 /* inhibit the header */ 814 display_header(No); 815 } 816 else if (newval > topn && topn == 0) 817 { 818 /* redraw the header */ 819 display_header(Yes); 820 d_header = i_header; 821 } 822 topn = newval; 823 } 824 break; 825 826 case CMD_delay: /* new seconds delay */ 827 new_message(MT_standout, "Seconds to delay: "); 828 if ((i = readline(tempbuf1, 8, Yes)) > -1) 829 { 830 delay = i; 831 } 832 clear_message(); 833 break; 834 835 case CMD_displays: /* change display count */ 836 new_message(MT_standout, 837 "Displays to show (currently %s): ", 838 displays == -1 ? "infinite" : 839 itoa(displays)); 840 if ((i = readline(tempbuf1, 10, Yes)) > 0) 841 { 842 displays = i; 843 } 844 else if (i == 0) 845 { 846 quit(0); 847 } 848 clear_message(); 849 break; 850 851 case CMD_kill: /* kill program */ 852 new_message(0, "kill "); 853 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) 854 { 855 if ((errmsg = kill_procs(tempbuf2)) != NULL) 856 { 857 new_message(MT_standout, "%s", errmsg); 858 putchar('\r'); 859 no_command = Yes; 860 } 861 } 862 else 863 { 864 clear_message(); 865 } 866 break; 867 868 case CMD_renice: /* renice program */ 869 new_message(0, "renice "); 870 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) 871 { 872 if ((errmsg = renice_procs(tempbuf2)) != NULL) 873 { 874 new_message(MT_standout, "%s", errmsg); 875 putchar('\r'); 876 no_command = Yes; 877 } 878 } 879 else 880 { 881 clear_message(); 882 } 883 break; 884 885 case CMD_idletog: 886 case CMD_idletog2: 887 ps.idle = !ps.idle; 888 new_message(MT_standout | MT_delayed, 889 " %sisplaying idle processes.", 890 ps.idle ? "D" : "Not d"); 891 putchar('\r'); 892 break; 893 894 case CMD_selftog: 895 ps.self = (ps.self == -1) ? getpid() : -1; 896 new_message(MT_standout | MT_delayed, 897 " %sisplaying self.", 898 (ps.self == -1) ? "D" : "Not d"); 899 putchar('\r'); 900 break; 901 902 case CMD_user: 903 new_message(MT_standout, 904 "Username to show: "); 905 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) 906 { 907 if (tempbuf2[0] == '+' && 908 tempbuf2[1] == '\0') 909 { 910 ps.uid = -1; 911 } 912 else if ((i = userid(tempbuf2)) == -1) 913 { 914 new_message(MT_standout, 915 " %s: unknown user", tempbuf2); 916 no_command = Yes; 917 } 918 else 919 { 920 ps.uid = i; 921 } 922 putchar('\r'); 923 } 924 else 925 { 926 clear_message(); 927 } 928 break; 929 930#ifdef ORDER 931 case CMD_order: 932 new_message(MT_standout, 933 "Order to sort: "); 934 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) 935 { 936 if ((i = string_index(tempbuf2, statics.order_names)) == -1) 937 { 938 new_message(MT_standout, 939 " %s: unrecognized sorting order", tempbuf2); 940 no_command = Yes; 941 } 942 else 943 { 944 order_index = i; 945 } 946 putchar('\r'); 947 } 948 else 949 { 950 clear_message(); 951 } 952 break; 953#endif 954 955 default: 956 new_message(MT_standout, " BAD CASE IN SWITCH!"); 957 putchar('\r'); 958 } 959 } 960 961 /* flush out stuff that may have been written */ 962 fflush(stdout); 963 } 964 } 965 } 966 } 967 968 quit(0); 969 /*NOTREACHED*/ 970} 971 972/* 973 * reset_display() - reset all the display routine pointers so that entire 974 * screen will get redrawn. 975 */ 976 977reset_display() 978 979{ 980 d_loadave = i_loadave; 981 d_procstates = i_procstates; 982 d_cpustates = i_cpustates; 983 d_memory = i_memory; 984 d_swap = i_swap; 985 d_message = i_message; 986 d_header = i_header; 987 d_process = i_process; 988} 989 990/* 991 * signal handlers 992 */ 993 994sigret_t leave() /* exit under normal conditions -- INT handler */ 995 996{ 997 leaveflag = 1; 998} 999 1000sigret_t tstop(i) /* SIGTSTP handler */ 1001 1002int i; 1003 1004{ 1005 tstopflag = 1; 1006} 1007 1008#ifdef SIGWINCH 1009sigret_t winch(i) /* SIGWINCH handler */ 1010 1011int i; 1012 1013{ 1014 winchflag = 1; 1015} 1016#endif 1017 1018void quit(status) /* exit under duress */ 1019 1020int status; 1021 1022{ 1023 end_screen(); 1024 exit(status); 1025 /*NOTREACHED*/ 1026} 1027 1028sigret_t onalrm() /* SIGALRM handler */ 1029 1030{ 1031 /* this is only used in batch mode to break out of the pause() */ 1032 /* return; */ 1033} 1034 1035