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 says the process crashed, but it still there
Forum Updated to NodeBB v4.3 + New Features

QProcess says the process crashed, but it still there

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.7k Views 2 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    I'm facing a weird behavior and I'm not sure if an xy problem.
    Using QProcess I run a console program:

        QProcess *process = new QProcess();
        connect(process, &QProcess::readyReadStandardOutput, this, &ManagerTask::task_readyReadStandardOutput);
        connect(process, &QProcess::readyReadStandardError, this, &ManagerTask::task_readyReadStandardError);
        connect(process, &QProcess::stateChanged, this, &ManagerTask::task_stateChanged);
        connect(process, &QProcess::errorOccurred, this, &ManagerTask::task_errorOccurred);
        process->start(_path, QIODevice::ReadWrite | QIODevice::Unbuffered);
    

    then every 1 s I send some data and read back the output via readyReadStandardOutput.
    It works fine for few seconds, then I get:

    • errorOccurred: Crashed
    • stateChanged: Not running

    But if I check with a terminal the process is still there:

    # ps aux | grep gaugeInt
    root      3131  0.1  0.1   1724   452 ?        S    04:32   0:00 /opt/bin/gaugeInt
    

    I tried to launch this application manually from a console. I sent the very same data using stdin and I didn't get any crash.
    What would you do to find out the cause of this behavior with QProcess?

    ODБOïO JonBJ 3 Replies Last reply
    0
    • M Mark81

      I'm facing a weird behavior and I'm not sure if an xy problem.
      Using QProcess I run a console program:

          QProcess *process = new QProcess();
          connect(process, &QProcess::readyReadStandardOutput, this, &ManagerTask::task_readyReadStandardOutput);
          connect(process, &QProcess::readyReadStandardError, this, &ManagerTask::task_readyReadStandardError);
          connect(process, &QProcess::stateChanged, this, &ManagerTask::task_stateChanged);
          connect(process, &QProcess::errorOccurred, this, &ManagerTask::task_errorOccurred);
          process->start(_path, QIODevice::ReadWrite | QIODevice::Unbuffered);
      

      then every 1 s I send some data and read back the output via readyReadStandardOutput.
      It works fine for few seconds, then I get:

      • errorOccurred: Crashed
      • stateChanged: Not running

      But if I check with a terminal the process is still there:

      # ps aux | grep gaugeInt
      root      3131  0.1  0.1   1724   452 ?        S    04:32   0:00 /opt/bin/gaugeInt
      

      I tried to launch this application manually from a console. I sent the very same data using stdin and I didn't get any crash.
      What would you do to find out the cause of this behavior with QProcess?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Mark81 said in QProcess says the process crashed, but it still there:

      What would you do to find out the cause

      i would Put the program in debug mode and try to find where it crashes exactly, then try analysis the trace or post it here

      M 1 Reply Last reply
      0
      • ODБOïO ODБOï

        @Mark81 said in QProcess says the process crashed, but it still there:

        What would you do to find out the cause

        i would Put the program in debug mode and try to find where it crashes exactly, then try analysis the trace or post it here

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

        @LeLev said in QProcess says the process crashed, but it still there:

        i would Put the program in debug mode and try to find where it crashes exactly, then try analysis the trace or post it here

        Perhaps I didn't understand your hint.
        Even if I put my application in debug mode, I just see the errorOccurred signal that fires. Because it is the external executable that "crashes" (at least this is what QProcess says, but it still is shown in the running processes) I have no way to understand what happened. And this binary comes from a third-party, I cannot put it in debug mode.

        1 Reply Last reply
        0
        • M Mark81

          I'm facing a weird behavior and I'm not sure if an xy problem.
          Using QProcess I run a console program:

              QProcess *process = new QProcess();
              connect(process, &QProcess::readyReadStandardOutput, this, &ManagerTask::task_readyReadStandardOutput);
              connect(process, &QProcess::readyReadStandardError, this, &ManagerTask::task_readyReadStandardError);
              connect(process, &QProcess::stateChanged, this, &ManagerTask::task_stateChanged);
              connect(process, &QProcess::errorOccurred, this, &ManagerTask::task_errorOccurred);
              process->start(_path, QIODevice::ReadWrite | QIODevice::Unbuffered);
          

          then every 1 s I send some data and read back the output via readyReadStandardOutput.
          It works fine for few seconds, then I get:

          • errorOccurred: Crashed
          • stateChanged: Not running

          But if I check with a terminal the process is still there:

          # ps aux | grep gaugeInt
          root      3131  0.1  0.1   1724   452 ?        S    04:32   0:00 /opt/bin/gaugeInt
          

          I tried to launch this application manually from a console. I sent the very same data using stdin and I didn't get any crash.
          What would you do to find out the cause of this behavior with QProcess?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @Mark81 said in QProcess says the process crashed, but it still there:

          then every 1 s I send some data and read back the output via readyReadStandardOutput.

          i thought crash could be caused by your read/write operations.

          but you say it is still running after the "crash", so can you, manually send commands or you have to restart it ?
          maybe it just hangs because of one of your sent commands

          M 1 Reply Last reply
          0
          • ODБOïO ODБOï

            @Mark81 said in QProcess says the process crashed, but it still there:

            then every 1 s I send some data and read back the output via readyReadStandardOutput.

            i thought crash could be caused by your read/write operations.

            but you say it is still running after the "crash", so can you, manually send commands or you have to restart it ?
            maybe it just hangs because of one of your sent commands

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

            @LeLev because I execute it with QProcess I see it in the process lists, but I don't know how to attach a terminal to its stdin.
            On the other side, if I launch the program manually from the console and send the same strings to it, it works fine and never "crashes".

            KroMignonK 1 Reply Last reply
            0
            • M Mark81

              I'm facing a weird behavior and I'm not sure if an xy problem.
              Using QProcess I run a console program:

                  QProcess *process = new QProcess();
                  connect(process, &QProcess::readyReadStandardOutput, this, &ManagerTask::task_readyReadStandardOutput);
                  connect(process, &QProcess::readyReadStandardError, this, &ManagerTask::task_readyReadStandardError);
                  connect(process, &QProcess::stateChanged, this, &ManagerTask::task_stateChanged);
                  connect(process, &QProcess::errorOccurred, this, &ManagerTask::task_errorOccurred);
                  process->start(_path, QIODevice::ReadWrite | QIODevice::Unbuffered);
              

              then every 1 s I send some data and read back the output via readyReadStandardOutput.
              It works fine for few seconds, then I get:

              • errorOccurred: Crashed
              • stateChanged: Not running

              But if I check with a terminal the process is still there:

              # ps aux | grep gaugeInt
              root      3131  0.1  0.1   1724   452 ?        S    04:32   0:00 /opt/bin/gaugeInt
              

              I tried to launch this application manually from a console. I sent the very same data using stdin and I didn't get any crash.
              What would you do to find out the cause of this behavior with QProcess?

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

              @Mark81
              To tell for sure whether it's really the same process running, you need to check for PID and/or zombie process.

              To replicate similarity to Qt state, when run gaugeInt from console redirect stdout & err to a pipe.

              Make 100% sure that your Qt spawning program does not e.g. let process or manager task go out of scope etc.

              If you think it would help to get a terminal onto process's stdin when launched from Qt, run it e.g. via xterm -e .... But situation will be different.

              M 1 Reply Last reply
              0
              • M Mark81

                @LeLev because I execute it with QProcess I see it in the process lists, but I don't know how to attach a terminal to its stdin.
                On the other side, if I launch the program manually from the console and send the same strings to it, it works fine and never "crashes".

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #7

                @Mark81 said in QProcess says the process crashed, but it still there:

                because I execute it with QProcess I see it in the process lists, but I don't know how to attach a terminal to its stdin.

                Maybe a silly question, but what is the content of _path? it is "/opt/bin/gaugeInt" or something else?

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                M 1 Reply Last reply
                0
                • JonBJ JonB

                  @Mark81
                  To tell for sure whether it's really the same process running, you need to check for PID and/or zombie process.

                  To replicate similarity to Qt state, when run gaugeInt from console redirect stdout & err to a pipe.

                  Make 100% sure that your Qt spawning program does not e.g. let process or manager task go out of scope etc.

                  If you think it would help to get a terminal onto process's stdin when launched from Qt, run it e.g. via xterm -e .... But situation will be different.

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

                  @JonB said in QProcess says the process crashed, but it still there:

                  @Mark81
                  To tell for sure whether it's really the same process running, you need to check for PID and/or zombie process.

                  Well, to better understand how QProcess works I did several trials and I'm more confused :o)

                  Let's call application A the executable that apparently crashes after a while, and B another executable that runs fine.
                  I discovered this:

                  • from my Qt application I start A and from the console I read it's PID (ps aux | grep <filename>). When QProcess says it has crashed, I check again from the console and the PID is the same.

                  • from my Qt application I start B and every second I send a command on its stdin (using QProcess::write). Some magic happens now. Every time I write something the console tells me a different PID, but QProcess::pid() and QProcess::processId() print every time the same value.

                  Definitely there is something beyond my knowledge here.

                  JonBJ 1 Reply Last reply
                  0
                  • KroMignonK KroMignon

                    @Mark81 said in QProcess says the process crashed, but it still there:

                    because I execute it with QProcess I see it in the process lists, but I don't know how to attach a terminal to its stdin.

                    Maybe a silly question, but what is the content of _path? it is "/opt/bin/gaugeInt" or something else?

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

                    @KroMignon yes, it's exactly that path.

                    1 Reply Last reply
                    0
                    • M Mark81

                      @JonB said in QProcess says the process crashed, but it still there:

                      @Mark81
                      To tell for sure whether it's really the same process running, you need to check for PID and/or zombie process.

                      Well, to better understand how QProcess works I did several trials and I'm more confused :o)

                      Let's call application A the executable that apparently crashes after a while, and B another executable that runs fine.
                      I discovered this:

                      • from my Qt application I start A and from the console I read it's PID (ps aux | grep <filename>). When QProcess says it has crashed, I check again from the console and the PID is the same.

                      • from my Qt application I start B and every second I send a command on its stdin (using QProcess::write). Some magic happens now. Every time I write something the console tells me a different PID, but QProcess::pid() and QProcess::processId() print every time the same value.

                      Definitely there is something beyond my knowledge here.

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

                      @Mark81
                      QProcess::processId() returns the native OS pid. Do not use/rely on QProcess::pid() (don't know what Qt version you are).

                      I don't know what you are seeing with your ps command line. It is possible that your process, gaugeInt, is spawning other processes to handle things, I don't know (try looking at parent/group/tty ids in the output, see if they are spawned by your first one?). Include the -f option on your command line to ps (check your distro man page) to get the full command-line, sometimes you can see information there to help distinguish any multiple instances.

                      1 Reply Last reply
                      1

                      • Login

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