C ++ application crashes after several hours

I have an application written in C ++ that uses opencv 2.0, curl and the opensurf library. First, the 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 which the script uses:

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

And it starts again. Well, after 800 or 900 repetitions, my icomparer starts to break. The system does not allow me to create more files in icomparer and in 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 &' 

And twisting doesn't work either:

 couldn't resolve host name (6) 

Everything is failing. I think that I am doing something wrong, for example, I don’t know if another PHP process is starting from the release resources of PHP processes.

In "icomparer" I close all open files. Maybe not releasing all the mutexes with mutex_destroy ... but in each iterator the C ++ application is closed, I think all things are released correctly?

What should I look for? I tried to control open files using stof.


  • Php 5.2
  • Centos 5.X
  • 1 GB RAM
  • 120 GB hard drive (4% used)
  • 4 x intel xeon
  • Is VPS (the machine has 16 GB of RAM).
  • The process opens 10 threads and combines them.
+1
source share
4 answers

On Unix-like systems, child processes inherit open parent file descriptors. However, when the child process ends, it closes all of its copies of the open file descriptors, but not the parent copies.

So, you open the file descriptors in the parent and do not close them. My bet is that you do not close the channels returned by proc_open() .

And you will also need to call proc_close() .

+3
source

It looks like you are missing file descriptors.

+4
source

Yes, it looks like you are opening processes, but not closing them after use, and it seems that they are not closing automatically (which may work in some cases).

Make sure you close / end the proc_close($res) process if you are no longer using the resource.

0
source

Your application does not close its files / sockets, you can try using syscall ulimit, while you can delete the number of open files allowed for each application. Take a look: man ulimit

-2
source

All Articles