Hi all,
I'm trying to fork a process under modperl for a web server, but I've
realized that the problem / misunderstanding that I'm having is
unrelated to modperl...I get the same problem under Perl. What I want
to do is to fork a child process (non-perl program), but also time how
long it runs. As I want the "user time" and not the real time, taking
the time stamp when it starts and stops is possible, but not ideal. So,
I think the only way to do this is to time it from the operating system
rather than within the program. This is what I have:
-----
#!/usr/bin/perl
use diagnostics;
use warnings;
use strict;
use POSIX 'setsid';
my $cmd = qq (/usr/bin/time --output=time.txt ls &);
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
$SIG{CHLD} = 'IGNORE';
defined (my $kid = fork) or die "Cannot fork: $!\n";
if ($kid) {
print "in parent whose kid is $kid\n";
}
else {
print "in child\n";
setsid () or die "Can't start a new session: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>tmp.file' or die "Can't write to tmpfile: $!";
open STDERR, '>&STDOUT' or die "Can't write to STDOUT: $!";
exec $cmd or die "Cannot execute exec: $!";
}
-----
When I run it, this is printed to stdout:
in child
in parent whose kid is 7122
time.txt is empty; and tmp.file has this:
test.pl
time.txt
tmp.file
/usr/bin/time: error waiting for child process: No child processes
I guess I have a misunderstanding of what fork does... Does anyone know
how I can get around this? I don't quite mind whether the time is
written to time.txt or to tmp.file...either will do... (Removing the
"&" and/or replacing "exec" with "system" yields the same result.)
Thank you!
Ray
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/