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