in reply to Re^8: system command - OK on 32 bit, fails on 64 bit Linux - why?
in thread system command - OK on 32 bit, fails on 64 bit Linux - why?

Hi - thanks for reporting the bug,
For what it's worth, I attach below my clean demo script, and also a demo of my workaround using a very crude daemon. For clarity I have omitted error checking. Similar daemon 100% OK in my real application running POV-Ray
Cheers, Peter

Demo script xpt5.pl
#!/usr/bin/perl #In this script the command system("date"); fails after 2 large arrays + have been setup. #The test machine has 4Gb RAM and 2.4 Gb swap. use strict; use warnings; my $i = 0; my $j = 0; my @array1 = ""; my @array2 = ""; my $cmd = ""; my $result = ""; my $doze = 15; system("free -m"); #Using system() print '#Before array setup - using system("date");: '; system("date"); printf "\n\$?=0x%x \$!=%s\n", $?, $!; #Setup big arrays for ($i = 1; $i <= 5760; $i++) { for ($j = 1; $j <= 2880; $j++) { $array1[$i][$j] = "<1234567890,1234567890,1234567890>"; $array2[$i][$j] = "<1234567890,1234567890,1234567890>"; } } print "#Finished setup of two arrays $i x $j\n#Going to sleep for $doz +e seconds - go and run free -m\n"; sleep $doze; print "#Awake again\n"; #Using system() print '#After array setup - using system("date");: '; system("date"); printf "\n\$?=0x%x \$!=%s\n", $?, $!; print "\n#End\n"; exit;
Demo script output:
./xpt5.pl total used free shared buffers cac +hed Mem: 3948 763 3185 0 42 +146 -/+ buffers/cache: 574 3374 Swap: 2392 36 2355 #Before array setup - using system("date");: Fri Feb 19 09:15:33 GMT 2 +010 $?=0x0 $!= #Finished setup of two arrays 5761 x 2881 #Going to sleep for 15 seconds - go and run free -m #Awake again #After array setup - using system("date");: $?=0x0 $!=Cannot allocate memory #End
free -m
total used free shared buffers cac +hed Mem: 3948 3927 21 0 42 +146 -/+ buffers/cache: 3738 210 Swap: 2392 36 2355

daemon.pl
#!/usr/bin/perl #Run this file in the background ./daemon.pl& #Then run ./xpt5a.pl use strict; use warnings; if ( -e "ready") {unlink ("ready")}; #in case ready exists while (1) { if ( !-e "ready" ) { sleep 2; } else { print "#After array setup - from the daemon: "; system("date"); printf "\n\$?=0x%x \$!=%s\n", $?, $!; system("free -m"); unlink ("ready"); } }
xpt5a.pl
#!/usr/bin/perl #First start the daemon in the background ./daemon.pl& #Then run this file ./xpt5a.pl use strict; use warnings; my $i = 0; my $j = 0; my @array1 = ""; my @array2 = ""; my $cmd = ""; my $result = ""; system("free -m"); #Using system() print '#Before array setup - using system("date");: '; system("date"); printf "\n\$?=0x%x \$!=%s\n", $?, $!; #Setup big arrays for ($i = 1; $i <= 5760; $i++) { for ($j = 1; $j <= 2880; $j++) { $array1[$i][$j] = "<1234567890,1234567890,1234567890>"; $array2[$i][$j] = "<1234567890,1234567890,1234567890>"; } } print "#Finished setup of two arrays $i x $j\n"; #Using daemon.pl - creating the ready file is the signal to the daemon open (READY, '>ready'); close (READY); #Wait for the daemon's reply - the daemon deletes ready when it has fi +nished while ( -e "ready" ) {sleep 2;} print "\n#End\n"; exit;
Output from ./daemon.pl ./xpt5a.pl
./daemon.pl& [3] 5270 dad@dad:/mnt/sda14/home/dad$ ./xpt5a.pl total used free shared buffers cac +hed Mem: 3948 762 3186 0 42 +146 -/+ buffers/cache: 573 3375 Swap: 2392 36 2355 #Before array setup - using system("date");: Fri Feb 19 09:14:43 GMT 2 +010 $?=0x0 $!= #Finished setup of two arrays 5761 x 2881 #After array setup - from the daemon: Fri Feb 19 09:14:55 GMT 2010 $?=0x0 $!=No such file or directory total used free shared buffers cac +hed Mem: 3948 3927 21 0 42 +146 -/+ buffers/cache: 3738 210 Swap: 2392 36 2355 #End