当脚本调用时程序冻结!

发布于 2024-11-18 21:49:55 字数 786 浏览 5 评论 0原文

我在发帖之前到处搜索,但找不到答案。

我需要计算算法执行时间的一些统计数据(平均、标准偏差等),所以我得到了这个 C++ 程序(bb .exe)启动算法并输出计算时间。

每当我从 shell 启动这个程序时,它都会花费一些时间,但工作正常。

由于执行速度不是很快,所以我编写了一个ac程序(CalculateStat),它使用system()调用

system("bb.exe > output.txt");

来多次执行之前的算法,然后计算所需的统计数据,所以我可以启动“./CalculateStat”并返回几个小时后就可以看到结果了。

CalculateStat 输出(在标准输出中)由 bb.exe 打印的每一行。

问题是,当CalculateStat启动bb.exe时,bb.exe会无缘无故地冻结(每6次计算冻结大约2次),所以我必须杀死它(ctrl+c)才能让CalculateStat继续运行。

起初,我认为这可能是“系统”调用的问题,所以我编写了一个 Perl 脚本,它做了几乎相同的事情,但我遇到了同样的问题。

有人有建议吗?

编辑 - 我认为问题可能是对输出文件的并发访问,所以我从“CalculateStat”中删除了读取文件的部分,只留下连续的调用。但它仍然冻结

编辑2-- 哇..这太奇怪了,所以我一直尝试从终端调用原始的 bb.exe,它也冻结在那里..现在我知道问题只是 bb 随机冻结,(它在测试期间从未冻结) ,它开始冻结统计计算..)

无论如何,现在这个问题没有意义..对不起大家:(

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 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.

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 :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

想念有你 2024-11-25 21:49:55

嗯,我不明白为什么你使用 C 程序来重复启动一个程序。不能直接从 shell 脚本执行此操作吗?如果再次冻结,搜索范围就会缩小。

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.

離人涙 2024-11-25 21:49:55

您应该能够使用 ps 命令查看该进程正在做什么。我的猜测是它阻塞了您没有重定向的“标准错误”文件句柄。 (使用 &> 而不是 > 将 stdout 和 stderr 重定向到文件。)

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.)

白日梦 2024-11-25 21:49:55

你怎么知道它被冻结了?文件中没有添加任何内容?这可能只是缓冲。大多数程序都会缓冲其输出,除非它们正在写入终端。

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.

天涯沦落人 2024-11-25 21:49:55

问题实际上是黑盒。当应用奇怪的参数时,它就冻结了,我通过对主程序进行一些检查解决了这个问题。谢谢大家!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文