Home > Archive > PERL Miscellaneous > October 2004 > Newbie needs help with forking
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie needs help with forking
|
|
| Michael Smith 2004-10-27, 8:56 pm |
| Hey Yall (from Tennessee you know),
Here is what I want to do:
Start a perl script which first forks a process that runs own it's
own. This child process will be a Oracle sqlldr job. This job will
run for about 30 mintes
While the sqlldr job is running return to the parent thread and start
running a bunch of database selects and OS commands to give me
statistics on the overall performance.
Once the sqlldr job completes stop collecting statistics and end the
script.
Anyone have an example close to that?
Thanks,
Mike
| |
| Michal Wojciechowski 2004-10-27, 8:56 pm |
| ms7530@yahoo.com (Michael Smith) writes:
> Start a perl script which first forks a process that runs own it's
> own. This child process will be a Oracle sqlldr job. This job will
> run for about 30 mintes
>
> While the sqlldr job is running return to the parent thread and
> start running a bunch of database selects and OS commands to give me
> statistics on the overall performance.
>
> Once the sqlldr job completes stop collecting statistics and end the
> script.
Assuming you know how to run the sqlldr job and how to generate the
statistics, the general scheme is quite simple:
use POSIX ":sys_wait_h"; # for WNOHANG
my $pid;
if ($pid = fork) {
# parent process
# repeatedly check if the child process is still running
while (waitpid($pid, WNOHANG) != $pid) {
#
# insert your statistics routines here
#
}
}
else {
die "Can't fork: $!" unless defined $pid;
# child process
#
# run sqlldr
#
}
You might want to put a sleep() call inside the while (waitpid...)
loop, to prevent it from being executed too often (and thus wasting
precious CPU cycles and making the whole operation slower).
HTH,
--
Michal Wojciechowski : for(<> ){/\s/,$l{$m=$`}=$'}$_ : 10 PRINT "Yet another"
odyniec()odyniec;net : =$l{$c},/O\s/?$c=$'-1:y/"//d : 20 PRINT "Perl hacker"
http://odyniec.net : ,/T\s/?print$':0while$c++<$m : 30 GOTO 10
|
|
|
|
|