沃梦达 / 编程问答 / php问题 / 正文

几个小时后 C++ 应用程序崩溃

C++ application collapsing after some hours(几个小时后 C++ 应用程序崩溃)

本文介绍了几个小时后 C++ 应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C++ 编写的应用程序,它使用 opencv 2.0、curl 和一个 opensurf 库.首先,一个 PHP 脚本 (cron.php) 调用 proc_open 并调用 C++ 应用程序(称为 icomparer).当它完成处理 N 图像返回组,说明哪些图像是相同的,之后脚本使用:

i have an application written in C++ that uses opencv 2.0, curl and a opensurf library. First a PHP script (cron.php) calls proc_open and calls the C++ application (called icomparer). When it finishes processing N images returns groups saying which images are the same, after that the script uses:

shell_exec('php cron.php > /dev/null 2>&1 &');  
die;

然后重新开始.好吧,在 800 或 900 次迭代后,我的 icomparer 开始崩溃.系统不允许我在 icomparer 和 php 脚本中创建更多文件.

And starts again. Well, after 800 or 900 iterates my icomparer starts breaking. The system don't lets me create more files, in icomparer and in the php script.

proc_open(): unable to create pipe Too many open files (2)
shell_exec(): Unable to execute 'php cron.php > /dev/null 2>&1 &'

curl 也失败了:

couldn't resolve host name (6)

一切都崩溃了.我认为我做错了什么,例如,我不知道是否从 PHP 进程释放资源启动另一个 PHP 进程.

Everything crashes. I think that i'm doing something wrong, for example, I dunno if starting another PHP process from a PHP process release resources.

在icomparer"中,我将关闭所有打开的文件.也许没有用 mutex_destroy 释放所有互斥锁...但是在每个迭代器中,c++ 应用程序都关闭了,我认为所有的东西都被释放了吗?

In "icomparer" I'm closing all opened files. Maybe not releasing all mutex with mutex_destroy... but in each iterator the c++ application is closed, I think that all stuff is released right?

我需要注意什么?我试过用 stof 监控打开的文件.

What I have to watch for? I have tried monitoring opened files with stof.

  • PHP 5.2
  • Centos 5.X
  • 1 GB 内存
  • 120 GB 硬盘(4% 已使用)
  • 4 x 英特尔至强
  • 是 VPS(机器有 16 GB 内存)
  • 该进程打开 10 个线程并加入它们.

推荐答案

在类 Unix 系统上,子进程继承父进程的打开文件描述符.但是,当子进程退出时,它会关闭所有打开的文件描述符的副本,但不会关闭父进程的副本.

On Unix-alike systems, child processes inherit the open file descriptors of the parent. However, when the child process exits, it does close all of its copies of the open file descriptors but not the parent's copies.

因此,您在父级中打开文件描述符而不是关闭它们.我敢打赌,您没有关闭 proc_open() 调用返回的管道.

So you are opening file descriptors in the parent and not closing them. My bet is that you are not closing the pipes returned by the proc_open() call.

您还需要调用 proc_close().

这篇关于几个小时后 C++ 应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:几个小时后 C++ 应用程序崩溃

基础教程推荐