Program started with QProcess results in Segmentation fault - works fine on console
-
wrote on 17 May 2012, 10:41 last edited by
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
-
wrote on 17 May 2012, 15:52 last edited by
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?
-
wrote on 17 May 2012, 16:21 last edited by
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
-
wrote on 18 May 2012, 07:11 last edited by
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
-
wrote on 18 May 2012, 09:42 last edited by
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.
-
wrote on 19 May 2012, 07:15 last edited by
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!
-
wrote on 22 May 2012, 16:45 last edited by
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/7