in reply to Re: Timer Question
in thread Timer Question

That's didn't work prefectly.

$ perl -e 'alarm(5); system("sleep 10; echo awoke")' Alarm clock $ awoke

system was interupted, but the command kept executing.

Replies are listed 'Best First'.
Re^3: Timer Question
by saintmike (Vicar) on Feb 17, 2006 at 00:59 UTC
    Depends on what is meant by "system call".

    If it's system call, it's a call to the OS, like sysread, in which case alarm works exactly as required.

    If it's "system() call", then things are different: system() forks a process, executes whatever's specified (different for single/multiple arguments), waits until the command is completed and then returns. It won't kill the spawned process, that's why it will run until the end.

      oh, yes, it does look like I misread the OP.
      it is a "system() call", how can I kill this after a certain amount of time...will alarm work per the other responses... Your help is greatly appreciated.
        On some systems, you can set an alarm on a child process like that:
        # instead of system("/foo/bar") do... my $pid = fork; if (defined $fork and not $fork) { alarm $timeout; exec "/foo/bar"; exit(1); # just in case exec fails. }