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. Program started with QProcess results in Segmentation fault - works fine on console
Forum Updated to NodeBB v4.3 + New Features

Program started with QProcess results in Segmentation fault - works fine on console

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.0k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SeniorSpielbergo
    wrote on 17 May 2012, 10:41 last edited by
    #1

    Hi,

    due to my bachelor thesis I have to start a complex native C++ program (sender) within a Qt program. The sender consists of about 50 threads and produces a lot of data which is send via a boost asio UDP socket.
    The idea is that I receive this data via an UDP socket (also boost asio) in my Qt program (receiver) and process it.
    I decided to use QProcess to start the sender, because it provides an easy way to keep track of the console outputs and all other important information about the sender.
    Starting the sender works fine as long I do not receive the data at the receiver side. In that case I get a segmentation fault on receiving.

    The project is meant to run under a Unix like operating system. First I developed under Cygwin and ran into that problem, then I switched to Ubuntu to search for memory leaks with valgrind, but could not find any.
    Thats when I realized by accident that sending and receiving is working perfectly (without any segmentation fault) when I start the sender in a console and not as a QProcess in the receiver.

    Long story made short, as I have to implement it the way I described it above (due to the assignement) I have to come up with a solution. So I am wondering why it is working one way but not the other way round.

    I have got a few starting points but have not found any answers to them:

    First of all I was wondering if there could be any memory limitations for QProcess that prevent me from handling these large amounts of data?
    Or maybe QProcess is overloaded with all threads running in the sender process?

    Any ideas on this are highly appreciated. If there are any questions regarding the setup of my program I try to answer them.
    Thanks in advance for any hints.

    Kind regards,

    David

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 17 May 2012, 15:52 last edited by
      #2

      I don't see why QProcess should have problems with a setup like this.

      Did you set up the environment (working directory, environment variables, etc.) properly before starting the process?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SeniorSpielbergo
        wrote on 17 May 2012, 16:21 last edited by
        #3

        Hi,

        thanks for your reply. I have set the working directory to the directory where my executable file is.
        But I have missed to set the evironment variables.
        I will have a look at that again tomorrow. I think that could be a very good point.

        I will report back if it worked.

        Thanks again,

        David

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SeniorSpielbergo
          wrote on 18 May 2012, 07:11 last edited by
          #4

          Hi,

          I checked if any environment variables need to be set, but it seems like the process just needs the standard variables like PATH.
          As far as I understand the QProcess reference they are set automatically if you do not set them explicit.
          Also setting them to the system environment variables did not do the trick.

          Kind regards,

          David

          1 Reply Last reply
          0
          • R Offline
            R Offline
            r3willia
            wrote on 18 May 2012, 09:42 last edited by
            #5

            A couple of things I would try - I have no idea if you've already tried to do any of this:

            • Attempt to get a call stack when the segfault happens; probably this will clarify what's going on.
            • Attempt to fake some data packets over UDP at low volumes to see if it is (as you suspect) an issue with volume of data.
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SeniorSpielbergo
              wrote on 19 May 2012, 07:15 last edited by
              #6

              I already produced small data packages to check whether it works or not. With small packets (just a 16 Byte header) it worked without problems.
              But since then my code changed a bit, maybe I try again on Monday (problem is, that I can only work on the code in university, because I am not allowed to copy it and use it at home).
              The output of valgrind did not help very much because I was not able to find any suspicious calls.

              Thanks for your ideas!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SeniorSpielbergo
                wrote on 22 May 2012, 16:45 last edited by
                #7

                Hi,
                today I tried to run my sender process with QProcess::startDetached() and it worked without any problems.
                Starting the same sender process as a normal QProcess with the start method results in a segmentation fault after receiving a few packets.
                I post the corresponding code, maybe somebody got an idea what I am doing wrong. I am not sure if it makes any difference, but I am running that program under Linux.
                Line 49 is the one that works if I comment out line 48 instead.

                Any comments are appreciated! Thanks in advance!

                P.S.: I am quiet sure that line 46 is not necessay but as I am running out of ideas I also tried this.

                @
                void ReceiverGui::startReceiver() {
                if (!settingsOk()) {
                return;
                }
                toogleStartStopButton();

                //! Start network
                setupAndStartNetwork();

                //! Determine receiver executable and working directory
                QString receiverFilePath = this->settings->value("receiverLocation").toString();
                QString receiverWorkingDirectory;
                QStringList receiverPathParts = receiverFilePath.split("/");
                for (int i = 0; i < receiverPathParts.size()-1; i++) {
                receiverWorkingDirectory.append(receiverPathParts.at(i));
                receiverWorkingDirectory.append("/");
                }
                QString receiverExecutableFile = "./" + receiverPathParts.at(receiverPathParts.size()-1);

                QStringList arguments;

                //! Start the receiver
                if (this->ui.settingsTabWidget->getLastSelectedMode() == SettingsTabWidget::EXTERNAL
                || this->ui.settingsTabWidget->getLastSelectedMode() == SettingsTabWidget::FILE)
                {
                //! determine file to decode
                QString inputFilePath;
                if (this->ui.settingsTabWidget->getLastSelectedMode() == SettingsTabWidget::EXTERNAL) {
                inputFilePath = this->ui.settingsTabWidget->getInputFileNonEvaluationPath();
                }
                else if(this->ui.settingsTabWidget->getLastSelectedMode() == SettingsTabWidget::FILE) {
                inputFilePath = this->ui.settingsTabWidget->getInputFileEvaluationPath();
                }
                inputFilePath = inputFilePath.left(inputFilePath.size()-6);
                arguments << inputFilePath;

                // determine plp number
                int plpNumber = this->ui.settingsTabWidget->getPlpNumber();
                arguments << QString::number(plpNumber);

                // determine xml config file
                QString configFilePath = this->settings->value("receiverConfigLocation").toString();
                arguments << configFilePath;

                //! start the process
                receiverProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
                receiverProcess->setWorkingDirectory(receiverWorkingDirectory);
                receiverProcess->start(receiverExecutableFile, arguments, QIODevice::ReadOnly);
                // QProcess::startDetached(receiverExecutableFile, arguments, receiverWorkingDirectory); //! works
                }
                else if (this->ui.settingsTabWidget->getLastSelectedMode() == SettingsTabWidget::REAL_TIME) {
                // ...
                }
                }
                @

                1 Reply Last reply
                0

                1/7

                17 May 2012, 10:41

                • Login

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