• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:


for (my $i = 0; $i < @files; $i++) {
    chomp (my $date = `date '+%m%d%y-%H:%M:%S'`);
    $file = $files[$i] . "_$date";
    `mv -f $path/$files[$i] $path/$file`;

#    exec("(/usr/local/bin/perl $path/email.pl $file) ");

    $::SIG{INT} = 'IGNORE';  # c 'turn undead' zombies
    unless(fork) {
        open STDIN,  "</dev/null";
        open STDOUT, ">/dev/null";
        exec(" /usr/local/bin/perl  $path/email.pl $file 2 > $path/output &");
        exit;  # This block only executes if we're the child, so exit when we're done.


i m running in background, but still when i run the above script, it erminates immidiately but  after that throws the output to prompt
1 Solution
-- It seems you are 'exec'ing over your parent, and not your child. The unless should be replaced by if.

> unless(fork)

doesnt distinguish between a failed fork and a parent process. You are better off using something like

my $pid ;
die("$! : Couldnt fork!!") unless defined($pid = fork) ;
if($pid) {
While we're at it, let's Perlise your very shell like code:


for (my $i = 0; $i < @files; $i++) {
   chomp (my $date = `date '+%m%d%y-%H:%M:%S'`);
   $file = $files[$i] . "_$date";
   `mv -f $path/$files[$i] $path/$file`;


use POSIX qw(strftime);

foreach my $file (@files) {
  my $date = strftime '+%m%d%y-%T',localtime;
  rename "$path/$file $path/${file}_$date" or warn "Can not rename $path/$file $!\n";

BTW, you would be better using a sensible, unambiguous, universal date format, ie: YYYYMMDD

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now