[user@notebook ~] time perl -e 'alarm shift @ARGV; exec @ARGV' 1 sleep 2
Alarm clock

real    0m1.004s
user    0m0.004s
sys 0m0.000s
[user@notebook ~] 

My question: how can I get rid of that "Alarm clock" message?? I just want to terminate a process after given time with a perl oneliner..

2 Answers 2


That message is from bash, not Perl.

One way is to run it in a subshell:

$ ( time perl -e 'alarm shift @ARGV; exec @ARGV' 1 sleep 2 )

real    0m1.004s
user    0m0.003s
sys 0m0.000s
  • Seems like it's the time command and subshell command that do this - I had to suppress stderr output as well to avoid the time output. Ended up quite messy compared to GNU timeout from coreutils.
    – RichVel
    Nov 16, 2017 at 15:51

If you want to run a command with a timeout, you may want to try the command timeout and avoid reinventing the wheel:

timeout 2 sleep 3

If you get an exit code of 124, the time has run out. Otherwise, you'll get the exit code of the executed command.

It's part of the GNU coreutils package, you're likely to already have it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .