Program freezes when called by script!
I searched everywhere before posting, but couldn't find an answer..
I need to calculate some statistics (Avg, St. Dev., etc.. ) for the execution time of an algorithm, so i have got this c++ program (bb.exe) that launches the algorithm and outputs the comp time.
Whenever i launch this program from the shell, it takes its time, but works fine.
Since the execution is not really fast, i wrote a c program (CalculateStat) that uses the system() call
system("bb.exe > output.txt");
to execute many times the previous algorithm and then calculates the needed statistics, so i can just launch "./CalculateStat" and come back a few hours later to see the results.
CalculateStat outputs ( in Standard Output ) every line printed by bb.exe.
The problem is that when CalculateStat launche开发者_运维知识库s bb.exe, it happens that bb.exe freezes with no reason (freezes about 2 times every 6 computations), so i have to kill it (ctrl+c) to let CalculateStat go on.
At first, i tought it could be a problem from the "system" call, so i wrote a perl script that did pretty much the same things, but i got the same problem.
Anyone has a suggestion?
EDIT-- I tought the problem might be the concurrent access to the output file, so i removed from "CalculateStat" the part reading the file, leaving only the consecutive calls.. But it still freezes
EDIT 2-- Wow.. It just got too weird, so i just kept trying to call the original bb.exe from the terminal, and it froze there too.. Now i know the problem was just the bb freezing randomly, (it never froze during tests, it started freezing on statistics calc.. )
Anyway, there's no point in this question now.. Sorry everyone :(
Hmmm I don't understand why your are using a C program to launch repeatedly a program. Can't you do this from a shell script directly. If it freezes again it'll narrow the scope of the search.
You should be able to see what the process is doing with the ps command. My guess is it is blocking on the "standard error" filehandle which you did not redirect. (use &> instead of > to redirect both stdout and stderr to a file.)
How do you know it's frozen? Nothing being added to the file? That could just be buffering. Most programs buffer their output unless they're writing to a terminal.
The problem was actually the Blackbox.. It was freezing when weird parameters were applied, and i solved it by using some checks on the main program. Thanks to everyone!
精彩评论