Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess cannot create pipe - Too many open files - but I don't understand why

QProcess cannot create pipe - Too many open files - but I don't understand why

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 604 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    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) 
            QTimer::singleShot(RECONNECTION_INTERVAL, this, &MyClass::ping);
    }
    

    I have 20 instances of this class, but usually only 1-2 runs the process in a given moment. Since:

    1. I store the QProcess object as a class member
    2. I catch the finished() signal

    I'm pretty sure I don't leave anything left open, do I?
    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 in a wrong way?

    Ubuntu 22.04, Qt 6.4.0. I saw this similar question, but I don't think it's the same scenario.

    JonBJ 1 Reply Last reply
    0
    • M Mark81

      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) 
              QTimer::singleShot(RECONNECTION_INTERVAL, this, &MyClass::ping);
      }
      

      I have 20 instances of this class, but usually only 1-2 runs the process in a given moment. Since:

      1. I store the QProcess object as a class member
      2. I catch the finished() signal

      I'm pretty sure I don't leave anything left open, do I?
      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 in a wrong way?

      Ubuntu 22.04, Qt 6.4.0. I saw this similar question, but I don't think it's the same scenario.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Mark81
      You could try QProcess::close() in your finished() slot.

      You could try making _processPing a QProcess *, allocating on heap, deleteLater() on finished().

      I would not be using an external program like ping to check whether a host is online, but that is a different matter.

      M 1 Reply Last reply
      0
      • JonBJ JonB

        @Mark81
        You could try QProcess::close() in your finished() slot.

        You could try making _processPing a QProcess *, allocating on heap, deleteLater() on finished().

        I would not be using an external program like ping to check whether a host is online, but that is a different matter.

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @JonB said in QProcess cannot create pipe - Too many open files - but I don't understand why:

        I would not be using an external program like ping to check whether a host is online, but that is a different matter.

        I'm interested! What other ways would you suggest? Until now I found using ping is the most reliable one.

        JonBJ 1 Reply Last reply
        0
        • M Mark81

          @JonB said in QProcess cannot create pipe - Too many open files - but I don't understand why:

          I would not be using an external program like ping to check whether a host is online, but that is a different matter.

          I'm interested! What other ways would you suggest? Until now I found using ping is the most reliable one.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Mark81
          There have been discussions about whether pinging a server is a useful thing to do. Mostly it seems better to do communications when you have something you actually want to communicate, and handle it not there or reconnecting at that time, not pinging to find out whether it is there or to keep connection open.

          There is also a possible alternative of send keep-alives on the socket instead.

          If I were going to do the "ping" approach, I would look to use Qt networking rather than an external ping program. Ping is pretty simple so you should not need an external program (with QProcess, checking what ping is outputting, etc.) to do what it does. For instance, http://www.ping127001.com/pingpage/ping.text is apparently the source of ping from 1983, doubtless there are other implementations in C++ if you Google.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved