On 2011-12-03, Cecil Westerhof <
Ce...@decebal.nl> wrote:
> Ik heb de volgende code:
> #!/usr/bin/env bash
..
> doTests
>
> Als doTests wordt aangeroepen (wat dezelfde code bevat als voor de
> functie aanroep) krijg ik:
> required time values with read: 4
> /home/cecil/bin/test2.sh: redirection error: cannot duplicate fd: Too many open files
> /home/cecil/bin/test2.sh: cannot make pipe for process substitution: Too many open files
> /home/cecil/bin/test2.sh: cannot make pipe for process substitution: Too many open files
> /home/cecil/bin/test2.sh: line 20: <(date '+%M %S %d'): ambiguous redirect
>
> Dus als ik de code op top level plaats werkt het prima, maar als
> ik het in een functie plaats, gaat het fout. Hoe komt dit?
>
> Als ik de code voor de functie aanroep verwijder, gaat het nog
> steeds fout. Het heeft er dus niet mee te maken dat de code voor
> een tweede keer wordt uitgevoerd.
Als ik de code uitvoer krijg ik dezelfde foutmelding, met in de logs:
denied resource overstep by requesting 1024 for RLIMIT_NOFILE against
limit 1024 for /bin/bash
Denk even aan de oude bekende "forkbug", meestal kun je met domme
programma's een pc wel plat of non-responsive krijgen.
Als ik "strace ./test.sh" uitvoer krijg ik veel uitvoer. Met LOOP_STEPS=2
wordt 4x open("/dev/fd/63", O_RDONLY) aangeroepen. 2x voor de main loop
en 2x voor de function loop.
In plaats van een test om snelheid van een functie te meten is dit meer
een test hoeveel files je mag openen.
Waarschijnlijk niet wat je uiteindelijk wil, maar kun je niet beter
'time' gebruiken om de tijd die een functie nodig heeft te testen?
Met vriendelijke groet,
Huub Reuver
$ strace ./test.sh 2> test.out
required time values with read: 1
required time values with read: 0
$ grep -i fd test.out
stat("/home/user", {st_mode=S_IFDIR|0755, st_size=24576, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=24576, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=24576, ...}) = 0
gettimeofday({1322990529, 949920}, NULL) = 0
fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
fcntl(255, F_SETFD, FD_CLOEXEC) = 0
wait4(-1, 0x38d6616fd44, WNOHANG, NULL) = -1 ECHILD (No child processes)
fcntl(63, F_GETFD) = -1 EBADF (Bad file descriptor)
open("/dev/fd/63", O_RDONLY) = 3
fcntl(0, F_GETFD) = 0
fcntl(0, F_DUPFD, 10) = 10
fcntl(0, F_GETFD) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
wait4(-1, 0x38d6616fdc4, WNOHANG, NULL) = -1 ECHILD (No child processes)
fcntl(10, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fcntl(63, F_GETFD) = -1 EBADF (Bad file descriptor)
open("/dev/fd/63", O_RDONLY) = 3
fcntl(0, F_GETFD) = 0
fcntl(0, F_DUPFD, 10) = 10
fcntl(0, F_GETFD) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
wait4(-1, 0x38d6616fdc4, WNOHANG, NULL) = -1 ECHILD (No child processes)
fcntl(10, F_GETFD) = 0x1 (flags FD_CLOEXEC)
wait4(-1, 0x38d6616fd44, WNOHANG, NULL) = -1 ECHILD (No child processes)
fcntl(63, F_GETFD) = -1 EBADF (Bad file descriptor)
open("/dev/fd/63", O_RDONLY) = 3
fcntl(0, F_GETFD) = 0
fcntl(0, F_DUPFD, 10) = 10
fcntl(0, F_GETFD) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
fcntl(10, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fcntl(63, F_GETFD) = 0
fcntl(62, F_GETFD) = -1 EBADF (Bad file descriptor)
open("/dev/fd/62", O_RDONLY) = 3
fcntl(0, F_GETFD) = 0
fcntl(0, F_DUPFD, 10) = 10
fcntl(0, F_GETFD) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
fcntl(10, F_GETFD) = 0x1 (flags FD_CLOEXEC)