You are not logged in.

1

Thursday, May 17th 2012, 12:27pm

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

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

2

Thursday, May 17th 2012, 6:34pm

If you have a seg fault problem, it would be wise to give more details around the circumstance, and relevant code, of the seg fault, than to ask for hand-wavy reasons.

QProcess doesn't have any 'memory' limitations Using sizeof(QProcess) should tell you that it's pretty small... All QProcess does is use native calls to start a process, and listen on some channels. It doesn't care about threads inside the process that it started.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Saturday, May 19th 2012, 8:23am

Thanks for your reply!

I thought it might be running somehow embedded in the other process and maybe would have limitations because of that. But eventually I thought it does not make much sense but wanted to be 100% sure.

On monday I will have another look with valgrind on the seg fault and if I can not come up with an solution I report back.
My problem is that I am only allowed to work on the code at university so I can not take it with me home.

4

Saturday, May 19th 2012, 10:14am

do you have remote access?

you shouldnt really need valgrind to find the cause of university project seg fault. just the debugger and some thinking
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

5

Saturday, May 19th 2012, 11:44am

Sadly I do not have remote access :(

I already spent 1 week debugging that program and then I asked my supervisor to have a look at it. He checked my code and could not find any errors either, so we decided to debug with valgrind because gdb was not any great help.

6

Saturday, May 19th 2012, 2:36pm

without any code we give any help except for talking in generalitites
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

7

Tuesday, May 22nd 2012, 8:50pm

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.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 <&lt; inputFilePath;

  // determine plp number
  int plpNumber = this-&gt;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) {
  // ...
 }
}