QProcess cannot create pipe even if all the processes are closed

33 views Asked by At

I use this function to check if an host is online:

MyClass.h

class MyClass : public QObject
{
    Q_OBJECT

public:
    explicit MyClass(QObject *parent = nullptr);

private:
    QProcess _processPing;

public slots:
    void ping();

private slots:
    void processPing_finished(int exitCode, QProcess::ExitStatus exitStatus);

};

MyClass.cpp

const int RECONNECTION_INTERVAL = 10000;

MyClass::MyClass(QObject *parent) : QObject(parent)
    connect(&_processPing, &QProcess::finished, this, &MyClass::processPing_finished);
}

void MyClass::ping()
{
    QStringList args;
    args << "-c" << "1" << "-W" << "1" << _url.host();
    _processPing.start("ping", args);
}

void MyClass::processPing_finished(int exitCode, QProcess::ExitStatus exitStatus)
{
    Q_UNUSED(exitStatus)

    _pingResult = exitCode == 0;
    if (!_pingResult)
    {
#ifdef DEBUG
        qInfo() << ID << _name << "Ping failed: offline";
#endif
        QTimer::singleShot(RECONNECTION_INTERVAL, this, &MyClass::ping);
    }
}

I have 30 instances of this class, but usually only 1-2 runs the process in a given moment. Since I store the QProcess object as a class member and I catch the finished() signal, I'm pretty sure I don't leave anything left open.

After some time I get this warning in the console:

error : QProcessPrivate::createPipe: Cannot create pipe : Too many open files

I don't understand why it happens. ps does not show any process running:

$ ps aux | grep ping
user       21768  0.0  0.0   6476  2316 pts/1    S+   17:35   0:00 grep --color=auto ping

I have to restart the application to be able again to run the ping process. Am I using QProcess wrong?

Ubuntu 22.04, Qt 6.4.0. I see this related question, but there is no accepted answer and most of them seem workarounds to me.

0

There are 0 answers