in reply to writing looped programs

In the spirit of TMOTOWTDI, you could, in your perl script have whatever you are trying to do be done within the context of a signal handler. For example,
#!/bin/perl $SIG{INT} = \&my_sub; sub my_sub { $SIG{INT} = \&my_sub; #do stuff } while (1) { #waiting for my signal... }

Then, put an entry in the crontab to send your process a SIGINT every minute (kill -INT (your pid here)). You may even be able to put the entry in the crontab through the script (I would try to figure it out myself, but I'm a bit sleepy right now). So, now with the signal handler installed, your script will "do stuff" only when it catches a <code>SIGINT<code>, which you've aranged to be once a minute. You also get the benefit of having your process be persistent, so that the loading of it into memory isn't an issue if it ever was to begin with.

thor

Replies are listed 'Best First'.
Re: Re: writing looped programs
by Biker (Priest) on Jan 30, 2002 at 14:32 UTC

    Generally speaking, you should try to make any signal handler as quick as ever possible.

    Current versions of Perl are not threadsafe, IIRC primarily because perl itself makes use of libraries that are not threadsafe.

    The potential problem is that if your long sub, executed by your signal handler, takes a lot of time then the signal handler may be called a second time. If this happens while perl is executing a system call that is not threadsafe you will get a core dump.

    "Livet är hårt" sa bonden.
    "Grymt" sa grisen...

      Of course, you could always have it fork off a child process if you expect the sub to run long. All depends on what you're trying to do...