A
A. Lewenberg
The following code forks creating a child process that does some
CPU-intensive task. The parent process loops every 1 second and
displays the results of a call to the times() function. What is
puzzling is that the last 2 elements of the times() function call
never get larger than zero even though they are supposed
to reflect cpu time usage of all child processes.
Is the times() function broken on this platform or am I
misunderstanding its use?
Thanks for any help or pointers.
Here is the output (note that the child process shows that it has used
more than 5 seconds of CPU but that the parent never thinks its
children have used any):
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Child times() result: 5.61 : 0.01 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
(Ctrl-C)
Here is the code:
$pid = fork() ;
if ($pid)
{
while (1)
{
my @xx = times() ;
print "Parent times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
sleep 1 ;
}
}
else
{
my ($i, $x) ;
for ($i=1; $i<= 9999999; ++$i)
{
$x = sin($i) ;
}
my @xx = times() ;
print "Child times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
exit 0 ;
}
In case it matters, here is the information on the perl version and
platform:
perl --version --> This is perl, v5.6.1 built for i386-linux
cat /etc/redhat-release --> Red Hat Linux release 7.2 (Enigma)
uname -a --> Linux cooper.library.uiuc.edu 2.4.20-27.7smp #1 SMP Thu
Dec 11 14:50:55 EST 2003 i686 unknown
(Note that I tried this on another 386 Linux platform running perl 5.8
with the same results.)
CPU-intensive task. The parent process loops every 1 second and
displays the results of a call to the times() function. What is
puzzling is that the last 2 elements of the times() function call
never get larger than zero even though they are supposed
to reflect cpu time usage of all child processes.
Is the times() function broken on this platform or am I
misunderstanding its use?
Thanks for any help or pointers.
Here is the output (note that the child process shows that it has used
more than 5 seconds of CPU but that the parent never thinks its
children have used any):
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Child times() result: 5.61 : 0.01 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
(Ctrl-C)
Here is the code:
$pid = fork() ;
if ($pid)
{
while (1)
{
my @xx = times() ;
print "Parent times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
sleep 1 ;
}
}
else
{
my ($i, $x) ;
for ($i=1; $i<= 9999999; ++$i)
{
$x = sin($i) ;
}
my @xx = times() ;
print "Child times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
exit 0 ;
}
In case it matters, here is the information on the perl version and
platform:
perl --version --> This is perl, v5.6.1 built for i386-linux
cat /etc/redhat-release --> Red Hat Linux release 7.2 (Enigma)
uname -a --> Linux cooper.library.uiuc.edu 2.4.20-27.7smp #1 SMP Thu
Dec 11 14:50:55 EST 2003 i686 unknown
(Note that I tried this on another 386 Linux platform running perl 5.8
with the same results.)