for finer control over processes, check out Proc::Simple
Please note that sub calc () is a subroutine, and not a process.
If you are calling this subroutine from some other place, then the regular behavior is what you have described:
#!/usr/bin/perl
# sub_trial.pl
use strict;
sub calc ()
{
print "in calc() now ... \n";
sleep 10; # wait for 10 seconds
# or do something here
}
print "we're in main script ... \n";
calc ();
print "and continued ... \n";
actually it is a little more complicated then my simple example, but
basically by the time the background process &calc finishes my page
has loaded, so I have to keep refreshing the page until &calc() finishes.
The reason for this is, once &calc enters values
into database, then final page can be reloaded only once instead of
multiple times.
Obviously, I will have to run it in a
unless(my $pid = fork()){&calc();}
or
something like that. When &calc() finishes reload page once.
Of course, as a CGI script is executed once for each HTTP request, you must keep the process ID you are monitoring somewhere, say on the filesystem or session.