I'd like Apache to terminate my perl script after 1 minute if it doesn't complete naturally. Is there a setting in Apache (or other server software) to do this?
4 Answers
CGIwrap does much of the stuff that suEXEC does (run the script under alternate permissions), but it also allows you to set resource limits:
--with-rlimit-cpu=SECONDS
limit cpu time with setrlimit
--with-rlimit-vmem=BYTES
limit total virtual memory with setrlimit
--with-rlimit-as=BYTES
limit total available memory with setrlimit
--with-rlimit-fsize=BYTES
limit writable file size with setrlimit
--with-rlimit-data=BYTES
limit data segment size with setrlimit
--with-rlimit-stack=BYTES
limit stack segment size with setrlimit
--with-rlimit-core=BYTES
limit core file size with setrlimit
--with-rlimit-rss=BYTES
limit resident set size with setrlimit
--with-rlimit-nproc=COUNT
limit number of processes with setrlimit
--with-rlimit-nofile=COUNT
limit number of open files with setrlimit
--with-rlimit-memlock=BYTES
limit lockable memory with setrlimit
Of the top of my head I can see two solutions (NOTE: I am a UNIX/Linux guy):
Make modifications to your perl code to set an alarm and then program a signal processor to capture the alarm and perform whatever processing you want.
You could manipulate the CPU limit of a process to terminate if it gets to 1 second CPU time. However, that real clock time length to get to 1 second of CPU time depends on your perl script.
You could always put "alarm 60;" at the top of your Perl scripts. However, this would require modifying all your Perl programs.