paulb@ttidca.TTI.COM (Paul Blumstein) (09/03/88)
I have a csh script that displays a menu & runs a program with different options depending on which menu line was selected. After program termination, the script loops back to the top and redisplays the menu. The program is basic a polling program that is terminated by catching a ^C, cleaning up & terminating. (It could also terminate on error conditions). The program has a debug mode that is toggled on & off by Quit signals (^\ key). The program works fine as a standalone (outside the script). The problem: I have "onintr" set in the script to loop the script back to the beginning when the user hits ^C. However, when ^\ is hit, the script core dumps, terminates leaving the program running as a background task. The man page for csh says "the shell generally ignores Quit signals". Generally seems to mean interactive shells, not shell scripts. I ended up re-writing the script as an sh script with a trap. I prefer csh, though. Does anyone have any idea how I could have accomplished this with csh??? Thanks in advance. Here is a sample script & prog (cut way down): ------------------------ cut here ---------------------- #! /bin/csh -f onintr start start: set choice="" echo "" echo "Which version do you wish to run?" echo " a. Version 1." echo " q. None -- exit this program" echo "" echo -n Enter letter: set choice=($<) if ($choice == "q") exit switch ($choice) case a: a.out breaksw default: echo Incorrect answer, please try again echo "" goto start breaksw endsw goto start ------------------------ cut here ---------------------- #include <stdio.h> #include <sys/time.h> #include <string.h> #include <signal.h> #include <ctype.h> #define FALSE 0 #define TRUE 1 #define LOOP_FOREVER for(;;) #define DEBUG if (debugsw) (void) printf static struct timeval clock; /* system clock */ static int debugsw = FALSE;/* debug switch */ int toggle_debug(); /* turns debug on & off */ int clean_up(); /* exits gracefully from ^C */ /*************************************************************************/ main() { static struct timeval timeout = {1, 0}; (void) signal(SIGQUIT, toggle_debug); /* catch ^\ key for debug */ (void) signal(SIGINT, clean_up); /* catch ^C key */ LOOP_FOREVER { (void) select(0, (int *) NULL, (int *) NULL, (int *) NULL, &timeout); } } /*************************************************************************/ toggle_debug() { debugsw = (debugsw ? FALSE : TRUE); /* toggle the debug state */ (void) printf("\nD>DEBUG turned %s\n", (debugsw ? "ON" : "OFF")); } /***************************************************************/ clean_up() { puts(""); printf("adios\n"); exit(0); } ============================================================================= Paul Blumstein | "I before E except after C" is weird. Citicorp/TTI | ^^ Santa Monica, CA +------------------------------------------------- {philabs,csun,psivax}!ttidca!paulb or paulb@ttidca.TTI.COM DISCLAIMER: My company automatically disagrees with everything I say.