There is on error in your code: sleep uses seconds as an argument. Until you want to wait forever you should choose a smaller value.
The way you handle your processes is a little bit awkward since you do not have any control over them after the forks are run. I cam up with a little script like this:

#!/usr/bin/perl -w use strict; sub sched{ my $file = shift || die "Missing parameter for subroutine call\n"; my $time = shift || die "Missing second parameter on subroutine call +\n"; my $cmd = `cat $file`; while (1){ print $cmd; sleep $time; } } # main program my $pid; # process id my @childs; # will hold all pids of our children $SIG{CHLD} = sub{wait}; # avoid Zombies $SIG{TERM} = sub{ kill -9, @childs; exit(0) }; # allow to end program by pressinc Ctrl-C or a kill call #this will hold all of our tasks my @tasks = ( { file => "msg.1", time => 10, }, { file => "msg.2", time => 2, }, { file => "msg.3", time => 5, }, ); # looping through the array of hashes and forking with each element FORLOOP: for my $i ( 0..$#tasks){ FORK: { if ($pid = fork){ # first fork # we are parent push @childs,$pid; next FORLOOP; }elsif (defined $pid){ # so we are a child sched($tasks[$i]{file},$tasks[$i]{time}); exit(0); # we should never reach this }elsif ($! =~/No more process/){ sleep 5; redo FORK; }else{ die "Something is rotten in the state or Denmark: $!\n"; } } } print "started all childs\n"; while (1){} # necessary so we can kill all of our childs

The hash is just a convenient way to handle all of your files, maybe you want to read those values from a file later. Also note the signal handling which enables you to stop the beasts with a control-c or a kill call.

Hope this helps,
C-Keen


In reply to forking and process control by C-Keen
in thread Reminder program by bsdbudha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.