user4035
user4035

Reputation: 23749

Perl: return execution to the caller but then wake up again

Suppose, we have a bash script:

#!/bin/bash

perl /home/user/myscript.pl
echo "hello"

myscript.pl:

#!/usr/bin/perl

print "First\n";
#here I want the script to sleep for 5 seconds
#and return the execution back to the caller
#so, "hello" will be printed
#but after 5 seconds the script will wake up from sleep and run the next line

print "Second\n";

How can I this?

Upvotes: 0

Views: 36

Answers (1)

ikegami
ikegami

Reputation: 386646

#!/bin/bash
perl /home/user/myscript.pl &
sleep 5
echo "hello"

#!/usr/bin/perl
...

-or-

#!/bin/bash
perl /home/user/myscript.pl
echo "hello"

#!/usr/bin/perl
sleep(5);
$SIG{CHLD} = 'IGNORE';
exit(0) if fork();
...

Upvotes: 2

Related Questions