简体   繁体   English

程序在被脚本调用时冻结!

[英]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.我需要为算法的执行时间计算一些统计数据(Avg、St. Dev.等),所以我有这个 c++ 程序(bb.exe),它启动算法并输出计算时间。

Whenever i launch this program from the shell, it takes its time, but works fine.每当我从 shell 启动这个程序时,它需要时间,但工作正常。

Since the execution is not really fast, i wrote a c program (CalculateStat) that uses the system() call由于执行速度不是很快,我编写了一个使用 system() 调用的 c 程序(CalculateStat)

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”并在几个小时后回来查看结果。

CalculateStat outputs ( in Standard Output ) every line printed by bb.exe. CalculateStat 输出(在标准 Output 中)由 bb.exe 打印的每一行。

The problem is that when CalculateStat launches 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.问题是当CalculateStat启动bb.exe时,bb.exe会无缘无故地冻结(每6次计算冻结大约2次),所以我必须杀死它(ctrl + c)才能让CalculateStat go打开。

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.起初,我认为这可能是“系统”调用的问题,所以我编写了一个 perl 脚本,它做了几乎相同的事情,但我遇到了同样的问题。

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编辑——我认为问题可能是对 output 文件的并发访问,所以我从“CalculateStat”中删除了读取文件的部分,只留下连续调用..但它仍然冻结

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.. )编辑2--哇..它太奇怪了,所以我一直试图从终端调用原始的bb.exe,它也冻结了..现在我知道问题只是bb随机冻结,(它在测试期间从未冻结,它开始在统计计算时冻结..)

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.嗯,我不明白你为什么使用 C 程序来重复启动一个程序。 Can't you do this from a shell script directly.您不能直接从 shell 脚本执行此操作。 If it freezes again it'll narrow the scope of the search.如果它再次冻结,它将缩小搜索的 scope。

You should be able to see what the process is doing with the ps command.您应该能够使用 ps 命令查看该进程正在执行的操作。 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.) (使用 &> 而不是 > 将 stdout 和 stderr 都重定向到文件。)

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.大多数程序会缓冲它们的 output ,除非它们正在写入终端。

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!谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM