Stephen Kellett writes: | In message <[EMAIL PROTECTED]>, Jon Freeman | <[EMAIL PROTECTED]> writes | >I had one for a while but took it down after some abc from somewhere caused | >abcm2ps to loop and I had my ISP phoning me up asking what abcm2ps was and | >telling me that it had been using something like 90% of the processing power | >for a good hour or more. I'm not prepared to take the chance on the shared | >server again. | | Write a monitor process that monitors your abcm2ps processes. Any | process that has been at a high CPU for more than X time, kill it. Or | modify abcm2ps to include a monitor thread to do the same task (better | as it'll know how long each tune processing has taken).
A monitoring process or thread is radical overkill for this task. We're talking about a C program. The standard C library handles the job almost trivially (as the term is understood by C programmers ;-). Here's a demo program that should run anywhere you have a minimally POSIX-compliant C library: /* * Demo of using the signal/alarm routines to interrupt a program that * runs for too long. */ #include <stdio.h> #include <signal.h> int timeout = 5; /* Kill the program after this many seconds */ sig_t alrm() { /* Alarm handler */ printf("Alarm!\n"); exit(0); /* Exit normally */ } main(ac,av) char **av; { int n = 0; signal(SIGALRM,(sig_t)alrm); /* Declare our alarm handler */ alarm(timeout); /* Set alarm timer */ while (++n) { printf("%d ...\n",n); sleep(1); } printf("Can't get here.\n"); exit(1); /* Paranoia */ } Supposedly even Windows has a POSIX-compliant C library, though I'd guess you'll find that this needs a bit of tweaking there. Anyway, this takes no extra process or thread. You should be able to copy the alrm() routine and the signal() and alarm() calls to any other C program to kill the program after some interval. To subscribe/unsubscribe, point your browser to: http://www.tullochgorm.com/lists.html