Fix a problem with the cd(4) driver -- the CAMGETPASSTHRU ioctl wouldn't
[dragonfly.git] / contrib / top / top.c
blob32cc2c8bca4fdd531190e0d568d30885b650e939
1 char *copyright =
2 "Copyright (c) 1984 through 1996, William LeFebvre";
4 /*
5 * Top users/processes display for Unix
6 * Version 3
8 * This program may be freely redistributed,
9 * but this entire comment MUST remain intact.
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
16 * $FreeBSD: src/contrib/top/top.c,v 1.4.6.5 2002/08/11 17:09:25 dwmalone Exp $
17 * $DragonFly: src/contrib/top/top.c,v 1.4 2006/10/03 12:20:11 y0netan1 Exp $
21 * See the file "Changes" for information on version-to-version changes.
25 * This file contains "main" and other high-level routines.
29 * The following preprocessor variables, when defined, are used to
30 * distinguish between different Unix implementations:
32 * SIGHOLD - use SVR4 sighold function when defined
33 * SIGRELSE - use SVR4 sigrelse function when defined
34 * FD_SET - macros FD_SET and FD_ZERO are used when defined
37 #include "os.h"
38 #include <errno.h>
39 #include <signal.h>
40 #include <setjmp.h>
41 #include <ctype.h>
42 #include <sys/time.h>
44 /* includes specific to top */
45 #include "display.h" /* interface to display package */
46 #include "screen.h" /* interface to screen package */
47 #include "top.h"
48 #include "top.local.h"
49 #include "boolean.h"
50 #include "machine.h"
51 #include "utils.h"
53 /* Size of the stdio buffer given to stdout */
54 #define Buffersize 2048
56 /* The buffer that stdio will use */
57 char stdoutbuf[Buffersize];
59 /* build Signal masks */
60 #define Smask(s) (1 << ((s) - 1))
62 /* for getopt: */
63 extern int optind;
64 extern char *optarg;
66 /* imported from screen.c */
67 extern int overstrike;
69 /* signal handling routines */
70 sigret_t leave();
71 sigret_t onalrm();
72 sigret_t tstop();
73 #ifdef SIGWINCH
74 sigret_t winch();
75 #endif
77 volatile sig_atomic_t leaveflag;
78 volatile sig_atomic_t tstopflag;
79 volatile sig_atomic_t winchflag;
81 /* internal routines */
82 void quit();
84 /* values which need to be accessed by signal handlers */
85 static int max_topn; /* maximum displayable processes */
87 /* miscellaneous things */
88 char *myname = "top";
89 jmp_buf jmp_int;
91 /* routines that don't return int */
93 char *username();
94 char *ctime();
95 char *kill_procs();
96 char *renice_procs();
98 #ifdef ORDER
99 extern int (*proc_compares[])();
100 #else
101 extern int proc_compare();
102 #endif
103 time_t time();
105 caddr_t get_process_info();
107 /* different routines for displaying the user's identification */
108 /* (values assigned to get_userid) */
109 char *username();
110 char *itoa7();
112 /* display routines that need to be predeclared */
113 int i_loadave();
114 int u_loadave();
115 int i_procstates();
116 int u_procstates();
117 int i_cpustates(struct system_info *);
118 int u_cpustates(struct system_info *);
119 int i_memory();
120 int u_memory();
121 int i_swap();
122 int u_swap();
123 int i_message();
124 int u_message();
125 int i_header();
126 int u_header();
127 int i_process();
128 int u_process();
130 /* pointers to display routines */
131 int (*d_loadave)() = i_loadave;
132 int (*d_procstates)() = i_procstates;
133 int (*d_cpustates)(struct system_info *) = i_cpustates;
134 int (*d_memory)() = i_memory;
135 int (*d_swap)() = i_swap;
136 int (*d_message)() = i_message;
137 int (*d_header)() = i_header;
138 int (*d_process)() = i_process;
140 int n_cpus = 0;
142 main(argc, argv)
144 int argc;
145 char *argv[];
148 register int i;
149 register int active_procs;
150 register int change;
152 struct system_info system_info;
153 struct statics statics;
154 caddr_t processes;
156 static char tempbuf1[50];
157 static char tempbuf2[50];
158 int old_sigmask; /* only used for BSD-style signals */
159 int topn = Default_TOPN;
160 int delay = Default_DELAY;
161 int displays = 0; /* indicates unspecified */
162 int sel_ret = 0;
163 time_t curr_time;
164 char *(*get_userid)() = username;
165 char *uname_field = "USERNAME";
166 char *header_text;
167 char *env_top;
168 char **preset_argv;
169 int preset_argc = 0;
170 char **av;
171 int ac;
172 char dostates = No;
173 char do_unames = Yes;
174 char interactive = Maybe;
175 char warnings = 0;
176 #if Default_TOPN == Infinity
177 char topn_specified = No;
178 #endif
179 char ch;
180 char *iptr;
181 char no_command = 1;
182 struct timeval timeout;
183 struct process_select ps;
184 #ifdef ORDER
185 char *order_name = NULL;
186 int order_index = 0;
187 #endif
188 #ifndef FD_SET
189 /* FD_SET and friends are not present: fake it */
190 typedef int fd_set;
191 #define FD_ZERO(x) (*(x) = 0)
192 #define FD_SET(f, x) (*(x) = 1<<f)
193 #endif
194 fd_set readfds;
196 #ifdef ORDER
197 static char command_chars[] = "\f qh?en#sdkriIutTOSo";
198 #else
199 static char command_chars[] = "\f qh?en#sdkriIutTOSO";
200 #endif
201 /* these defines enumerate the "strchr"s of the commands in command_chars */
202 #define CMD_redraw 0
203 #define CMD_update 1
204 #define CMD_quit 2
205 #define CMD_help1 3
206 #define CMD_help2 4
207 #define CMD_OSLIMIT 4 /* terminals with OS can only handle commands */
208 #define CMD_errors 5 /* less than or equal to CMD_OSLIMIT */
209 #define CMD_number1 6
210 #define CMD_number2 7
211 #define CMD_delay 8
212 #define CMD_displays 9
213 #define CMD_kill 10
214 #define CMD_renice 11
215 #define CMD_idletog 12
216 #define CMD_idletog2 13
217 #define CMD_user 14
218 #define CMD_selftog 15
219 #define CMD_threads 16
220 #define CMD_othreads 17
221 #define CMD_system 18
222 #ifdef ORDER
223 #define CMD_order 19
224 #endif
226 /* set the buffer for stdout */
227 #ifdef DEBUG
228 extern FILE *debug;
229 debug = fopen("debug.run", "w");
230 setbuffer(stdout, NULL, 0);
231 #else
232 setbuffer(stdout, stdoutbuf, Buffersize);
233 #endif
235 /* get our name */
236 if (argc > 0)
238 if ((myname = strrchr(argv[0], '/')) == 0)
240 myname = argv[0];
242 else
244 myname++;
248 /* initialize some selection options */
249 ps.idle = Yes;
250 ps.self = -1;
251 ps.system = No;
252 ps.threads = No;
253 ps.only_threads = No;
254 ps.uid = -1;
255 ps.command = NULL;
257 /* get preset options from the environment */
258 if ((env_top = getenv("TOP")) != NULL)
260 av = preset_argv = argparse(env_top, &preset_argc);
261 ac = preset_argc;
263 /* set the dummy argument to an explanatory message, in case
264 getopt encounters a bad argument */
265 preset_argv[0] = "while processing environment";
268 /* process options */
269 do {
270 /* if we're done doing the presets, then process the real arguments */
271 if (preset_argc == 0)
273 ac = argc;
274 av = argv;
276 /* this should keep getopt happy... */
277 optind = 1;
280 while ((i = getopt(ac, av, "SITONbinquvs:d:U:o:t")) != EOF)
282 switch(i)
284 case 'v': /* show version number */
285 fprintf(stderr, "%s: version %s\n",
286 myname, version_string());
287 exit(1);
288 break;
290 case 'u': /* toggle uid/username display */
291 do_unames = !do_unames;
292 break;
294 case 'U': /* display only username's processes */
295 if ((ps.uid = userid(optarg)) == -1)
297 fprintf(stderr, "%s: unknown user\n", optarg);
298 exit(1);
300 break;
302 case 'S': /* show system processes */
303 ps.system = !ps.system;
304 break;
306 case 'I': /* show idle processes */
307 ps.idle = !ps.idle;
308 break;
310 case 'O':
311 ps.only_threads = !ps.only_threads; /* only threads */
312 break;
314 case 'T':
315 ps.threads = !ps.threads; /* show threads */
316 break;
318 case 'i': /* go interactive regardless */
319 interactive = Yes;
320 break;
322 case 'n': /* batch, or non-interactive */
323 case 'b':
324 interactive = No;
325 break;
327 case 'd': /* number of displays to show */
328 if ((i = atoiwi(optarg)) == Invalid || i == 0)
330 fprintf(stderr,
331 "%s: warning: display count should be positive -- option ignored\n",
332 myname);
333 warnings++;
335 else
337 displays = i;
339 break;
341 case 's':
342 if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0))
344 fprintf(stderr,
345 "%s: warning: seconds delay should be positive -- using default\n",
346 myname);
347 delay = Default_DELAY;
348 warnings++;
350 break;
352 case 'q': /* be quick about it */
353 /* only allow this if user is really root */
354 if (getuid() == 0)
356 /* be very un-nice! */
357 (void) nice(-20);
359 else
361 fprintf(stderr,
362 "%s: warning: `-q' option can only be used by root\n",
363 myname);
364 warnings++;
366 break;
368 case 'o': /* select sort order */
369 #ifdef ORDER
370 order_name = optarg;
371 #else
372 fprintf(stderr,
373 "%s: this platform does not support arbitrary ordering. Sorry.\n",
374 myname);
375 warnings++;
376 #endif
377 break;
379 case 't':
380 ps.self = (ps.self == -1) ? getpid() : -1;
381 break;
383 default:
384 fprintf(stderr, "\
385 Top version %s\n\
386 Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
387 version_string(), myname);
388 exit(1);
392 /* get count of top processes to display (if any) */
393 if (optind < ac)
395 if ((topn = atoiwi(av[optind])) == Invalid)
397 fprintf(stderr,
398 "%s: warning: process display count should be non-negative -- using default\n",
399 myname);
400 warnings++;
402 #if Default_TOPN == Infinity
403 else
405 topn_specified = Yes;
407 #endif
410 /* tricky: remember old value of preset_argc & set preset_argc = 0 */
411 i = preset_argc;
412 preset_argc = 0;
414 /* repeat only if we really did the preset arguments */
415 } while (i != 0);
417 /* set constants for username/uid display correctly */
418 if (!do_unames)
420 uname_field = " UID ";
421 get_userid = itoa7;
424 /* initialize the kernel memory interface */
425 if (machine_init(&statics) == -1)
427 exit(1);
430 #ifdef ORDER
431 /* determine sorting order index, if necessary */
432 if (order_name != NULL)
434 if ((order_index = string_index(order_name, statics.order_names)) == -1)
436 char **pp;
438 fprintf(stderr, "%s: '%s' is not a recognized sorting order.\n",
439 myname, order_name);
440 fprintf(stderr, "\tTry one of these:");
441 pp = statics.order_names;
442 while (*pp != NULL)
444 fprintf(stderr, " %s", *pp++);
446 fputc('\n', stderr);
447 exit(1);
450 #endif
452 #ifdef no_initialization_needed
453 /* initialize the hashing stuff */
454 if (do_unames)
456 init_hash();
458 #endif
460 /* initialize termcap */
461 init_termcap(interactive);
463 /* get the string to use for the process area header */
464 header_text = format_header(uname_field);
466 /* initialize display interface */
467 if ((max_topn = display_init(&statics)) == -1)
469 fprintf(stderr, "%s: can't allocate sufficient memory\n", myname);
470 exit(4);
473 /* print warning if user requested more processes than we can display */
474 if (topn > max_topn)
476 fprintf(stderr,
477 "%s: warning: this terminal can only display %d processes.\n",
478 myname, max_topn);
479 warnings++;
482 /* adjust for topn == Infinity */
483 if (topn == Infinity)
486 * For smart terminals, infinity really means everything that can
487 * be displayed, or Largest.
488 * On dumb terminals, infinity means every process in the system!
489 * We only really want to do that if it was explicitly specified.
490 * This is always the case when "Default_TOPN != Infinity". But if
491 * topn wasn't explicitly specified and we are on a dumb terminal
492 * and the default is Infinity, then (and only then) we use
493 * "Nominal_TOPN" instead.
495 #if Default_TOPN == Infinity
496 topn = smart_terminal ? Largest :
497 (topn_specified ? Largest : Nominal_TOPN);
498 #else
499 topn = Largest;
500 #endif
503 /* set header display accordingly */
504 display_header(topn > 0);
506 /* determine interactive state */
507 if (interactive == Maybe)
509 interactive = smart_terminal;
512 /* if # of displays not specified, fill it in */
513 if (displays == 0)
515 displays = smart_terminal ? Infinity : 1;
518 /* hold interrupt signals while setting up the screen and the handlers */
519 #ifdef SIGHOLD
520 sighold(SIGINT);
521 sighold(SIGQUIT);
522 sighold(SIGTSTP);
523 #else
524 old_sigmask = sigblock(Smask(SIGINT) | Smask(SIGQUIT) | Smask(SIGTSTP));
525 #endif
526 init_screen();
527 (void) signal(SIGINT, leave);
528 (void) signal(SIGQUIT, leave);
529 (void) signal(SIGTSTP, tstop);
530 #ifdef SIGWINCH
531 (void) signal(SIGWINCH, winch);
532 #endif
533 #ifdef SIGRELSE
534 sigrelse(SIGINT);
535 sigrelse(SIGQUIT);
536 sigrelse(SIGTSTP);
537 #else
538 (void) sigsetmask(old_sigmask);
539 #endif
540 if (warnings)
542 fputs("....", stderr);
543 fflush(stderr); /* why must I do this? */
544 sleep((unsigned)(3 * warnings));
545 fputc('\n', stderr);
548 restart:
551 * main loop -- repeat while display count is positive or while it
552 * indicates infinity (by being -1)
555 while ((displays == -1) || (displays-- > 0))
557 /* get the current stats */
558 get_system_info(&system_info);
560 /* get the current set of processes */
561 processes =
562 get_process_info(&system_info,
563 &ps,
564 #ifdef ORDER
565 proc_compares[order_index]);
566 #else
567 proc_compare);
568 #endif
570 /* display the load averages */
571 (*d_loadave)(system_info.last_pid,
572 system_info.load_avg);
574 /* display the current time */
575 /* this method of getting the time SHOULD be fairly portable */
576 time(&curr_time);
577 i_uptime(&system_info.boottime, &curr_time);
578 i_timeofday(&curr_time);
580 /* display process state breakdown */
581 (*d_procstates)(system_info.p_total,
582 system_info.procstates);
584 /* display the cpu state percentage breakdown */
585 if (dostates) /* but not the first time */
587 (*d_cpustates)(&system_info);
589 else
591 /* we'll do it next time */
592 if (smart_terminal)
594 z_cpustates(&system_info);
596 else
598 putchar('\n');
600 dostates = Yes;
603 /* display memory stats */
604 (*d_memory)(system_info.memory);
606 /* display swap stats */
607 (*d_swap)(system_info.swap);
609 /* handle message area */
610 (*d_message)();
612 /* update the header area */
613 (*d_header)(header_text);
615 if (topn > 0)
617 /* determine number of processes to actually display */
618 /* this number will be the smallest of: active processes,
619 number user requested, number current screen accomodates */
620 active_procs = system_info.P_ACTIVE;
621 if (active_procs > topn)
623 active_procs = topn;
625 if (active_procs > max_topn)
627 active_procs = max_topn;
630 /* now show the top "n" processes. */
631 for (i = 0; i < active_procs; i++)
633 (*d_process)(i, format_next_process(processes, get_userid));
636 else
638 i = 0;
641 /* do end-screen processing */
642 u_endscreen(i);
644 /* now, flush the output buffer */
645 if (fflush(stdout) != 0)
647 new_message(MT_standout, " Write error on stdout");
648 putchar('\r');
649 quit(1);
650 /*NOTREACHED*/
653 /* only do the rest if we have more displays to show */
654 if (displays)
656 /* switch out for new display on smart terminals */
657 if (smart_terminal)
659 if (overstrike)
661 reset_display();
663 else
665 d_loadave = u_loadave;
666 d_procstates = u_procstates;
667 d_cpustates = i_cpustates;
668 d_memory = u_memory;
669 d_swap = u_swap;
670 d_message = u_message;
671 d_header = u_header;
672 d_process = u_process;
676 no_command = Yes;
677 if (!interactive)
679 /* set up alarm */
680 (void) signal(SIGALRM, onalrm);
681 (void) alarm((unsigned)delay);
683 /* wait for the rest of it .... */
684 pause();
686 else while (no_command)
688 /* assume valid command unless told otherwise */
689 no_command = No;
691 /* set up arguments for select with timeout */
692 FD_ZERO(&readfds);
693 FD_SET(0, &readfds); /* for standard input */
694 timeout.tv_sec = delay;
695 timeout.tv_usec = 0;
697 if (leaveflag) {
698 end_screen();
699 exit(0);
702 if (tstopflag) {
703 /* move to the lower left */
704 end_screen();
705 fflush(stdout);
707 /* default the signal handler action */
708 (void) signal(SIGTSTP, SIG_DFL);
710 /* unblock the signal and send ourselves one */
711 #ifdef SIGRELSE
712 sigrelse(SIGTSTP);
713 #else
714 (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1)));
715 #endif
716 (void) kill(0, SIGTSTP);
718 /* reset the signal handler */
719 (void) signal(SIGTSTP, tstop);
721 /* reinit screen */
722 reinit_screen();
723 reset_display();
724 tstopflag = 0;
725 goto restart;
728 if (winchflag) {
729 /* reascertain the screen dimensions */
730 get_screensize();
732 /* tell display to resize */
733 max_topn = display_resize();
735 /* reset the signal handler */
736 (void) signal(SIGWINCH, winch);
738 reset_display();
739 winchflag = 0;
740 goto restart;
743 /* wait for either input or the end of the delay period */
744 sel_ret = select(2, &readfds, NULL, NULL, &timeout);
745 if (sel_ret < 0 && errno != EINTR)
746 quit(0);
747 if (sel_ret > 0)
749 int newval;
750 char *errmsg;
752 /* something to read -- clear the message area first */
753 clear_message();
755 /* now read it and convert to command strchr */
756 /* (use "change" as a temporary to hold strchr) */
757 if (read(0, &ch, 1) != 1)
759 /* read error: either 0 or -1 */
760 new_message(MT_standout, " Read error on stdin");
761 putchar('\r');
762 quit(1);
763 /*NOTREACHED*/
765 if ((iptr = strchr(command_chars, ch)) == NULL)
767 if (ch != '\r' && ch != '\n')
769 /* illegal command */
770 new_message(MT_standout, " Command not understood");
772 putchar('\r');
773 no_command = Yes;
775 else
777 change = iptr - command_chars;
778 if (overstrike && change > CMD_OSLIMIT)
780 /* error */
781 new_message(MT_standout,
782 " Command cannot be handled by this terminal");
783 putchar('\r');
784 no_command = Yes;
786 else switch(change)
788 case CMD_redraw: /* redraw screen */
789 reset_display();
790 break;
792 case CMD_update: /* merely update display */
793 /* is the load average high? */
794 if (system_info.load_avg[0] > LoadMax)
796 /* yes, go home for visual feedback */
797 go_home();
798 fflush(stdout);
800 break;
802 case CMD_quit: /* quit */
803 quit(0);
804 /*NOTREACHED*/
805 break;
807 case CMD_help1: /* help */
808 case CMD_help2:
809 reset_display();
810 clear();
811 show_help();
812 standout("Hit any key to continue: ");
813 fflush(stdout);
814 (void) read(0, &ch, 1);
815 break;
817 case CMD_errors: /* show errors */
818 if (error_count() == 0)
820 new_message(MT_standout,
821 " Currently no errors to report.");
822 putchar('\r');
823 no_command = Yes;
825 else
827 reset_display();
828 clear();
829 show_errors();
830 standout("Hit any key to continue: ");
831 fflush(stdout);
832 (void) read(0, &ch, 1);
834 break;
836 case CMD_number1: /* new number */
837 case CMD_number2:
838 new_message(MT_standout,
839 "Number of processes to show: ");
840 newval = readline(tempbuf1, 8, Yes);
841 if (newval > -1)
843 if (newval > max_topn)
845 new_message(MT_standout | MT_delayed,
846 " This terminal can only display %d processes.",
847 max_topn);
848 putchar('\r');
851 if (newval == 0)
853 /* inhibit the header */
854 display_header(No);
856 else if (newval > topn && topn == 0)
858 /* redraw the header */
859 display_header(Yes);
860 d_header = i_header;
862 topn = newval;
864 break;
866 case CMD_delay: /* new seconds delay */
867 new_message(MT_standout, "Seconds to delay: ");
868 if ((i = readline(tempbuf1, 8, Yes)) > -1)
870 if ((delay = i) == 0 && getuid() != 0)
872 delay = 1;
875 clear_message();
876 break;
878 case CMD_displays: /* change display count */
879 new_message(MT_standout,
880 "Displays to show (currently %s): ",
881 displays == -1 ? "infinite" :
882 itoa(displays));
883 if ((i = readline(tempbuf1, 10, Yes)) > 0)
885 displays = i;
887 else if (i == 0)
889 quit(0);
891 clear_message();
892 break;
894 case CMD_kill: /* kill program */
895 new_message(0, "kill ");
896 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
898 if ((errmsg = kill_procs(tempbuf2)) != NULL)
900 new_message(MT_standout, "%s", errmsg);
901 putchar('\r');
902 no_command = Yes;
905 else
907 clear_message();
909 break;
911 case CMD_renice: /* renice program */
912 new_message(0, "renice ");
913 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
915 if ((errmsg = renice_procs(tempbuf2)) != NULL)
917 new_message(MT_standout, "%s", errmsg);
918 putchar('\r');
919 no_command = Yes;
922 else
924 clear_message();
926 break;
928 case CMD_idletog:
929 case CMD_idletog2:
930 ps.idle = !ps.idle;
931 new_message(MT_standout | MT_delayed,
932 " %sisplaying idle processes.",
933 ps.idle ? "D" : "Not d");
934 putchar('\r');
935 break;
937 case CMD_selftog:
938 ps.self = (ps.self == -1) ? getpid() : -1;
939 new_message(MT_standout | MT_delayed,
940 " %sisplaying self.",
941 (ps.self == -1) ? "D" : "Not d");
942 putchar('\r');
943 break;
945 case CMD_threads:
946 ps.threads = !ps.threads;
947 new_message(MT_standout | MT_delayed,
948 " %sisplaying threads.",
949 ps.threads ? "D" : "Not d");
950 putchar('\r');
951 break;
953 case CMD_othreads:
954 ps.only_threads = !ps.only_threads;
955 new_message(MT_standout | MT_delayed,
956 ps.only_threads ?
957 "Only displaying threads." :
958 "Displaying threads and processes.");
959 putchar('\r');
960 break;
962 case CMD_system:
963 ps.system = !ps.system;
964 new_message(MT_standout | MT_delayed,
965 " %sisplaying system processes.",
966 ps.system ? "D" : "Not d");
967 putchar('\r');
968 break;
970 case CMD_user:
971 new_message(MT_standout,
972 "Username to show: ");
973 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
975 if (tempbuf2[0] == '+' &&
976 tempbuf2[1] == '\0')
978 ps.uid = -1;
980 else if ((i = userid(tempbuf2)) == -1)
982 new_message(MT_standout,
983 " %s: unknown user", tempbuf2);
984 no_command = Yes;
986 else
988 ps.uid = i;
990 putchar('\r');
992 else
994 clear_message();
996 break;
998 #ifdef ORDER
999 case CMD_order:
1000 new_message(MT_standout,
1001 "Order to sort: ");
1002 if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
1004 if ((i = string_index(tempbuf2, statics.order_names)) == -1)
1006 new_message(MT_standout,
1007 " %s: unrecognized sorting order", tempbuf2);
1008 no_command = Yes;
1010 else
1012 order_index = i;
1014 putchar('\r');
1016 else
1018 clear_message();
1020 break;
1021 #endif
1023 default:
1024 new_message(MT_standout, " BAD CASE IN SWITCH!");
1025 putchar('\r');
1029 /* flush out stuff that may have been written */
1030 fflush(stdout);
1036 #ifdef DEBUG
1037 fclose(debug);
1038 #endif
1039 quit(0);
1040 /*NOTREACHED*/
1044 * reset_display() - reset all the display routine pointers so that entire
1045 * screen will get redrawn.
1048 reset_display()
1051 d_loadave = i_loadave;
1052 d_procstates = i_procstates;
1053 d_cpustates = i_cpustates;
1054 d_memory = i_memory;
1055 d_swap = i_swap;
1056 d_message = i_message;
1057 d_header = i_header;
1058 d_process = i_process;
1062 * signal handlers
1065 sigret_t leave() /* exit under normal conditions -- INT handler */
1068 leaveflag = 1;
1071 sigret_t tstop(i) /* SIGTSTP handler */
1073 int i;
1076 tstopflag = 1;
1079 #ifdef SIGWINCH
1080 sigret_t winch(i) /* SIGWINCH handler */
1082 int i;
1085 winchflag = 1;
1087 #endif
1089 void quit(status) /* exit under duress */
1091 int status;
1094 end_screen();
1095 exit(status);
1096 /*NOTREACHED*/
1099 sigret_t onalrm() /* SIGALRM handler */
1102 /* this is only used in batch mode to break out of the pause() */
1103 /* return; */