Unsolved QProcess says the process crashed, but it still there
-
I'm facing a weird behavior and I'm not sure if an
xy
problem.
UsingQProcess
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 withQProcess
? -
@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
-
@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 theerrorOccurred
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. -
@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 -
@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 itsstdin
.
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". -
@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. -
@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? -
@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>
). WhenQProcess
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
(usingQProcess::write
). Some magic happens now. Every time I write something the console tells me a different PID, butQProcess::pid()
andQProcess::processId()
print every time the same value.
Definitely there is something beyond my knowledge here.
-
-
@KroMignon yes, it's exactly that path.
-
@Mark81
QProcess::processId()
returns the native OS pid. Do not use/rely onQProcess::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 tops
(check your distroman
page) to get the full command-line, sometimes you can see information there to help distinguish any multiple instances.