qt-interest@trolltech.com
[Top] [All Lists]

Re: Segmentation fault caused by QProcess::start()

Subject: Re: Segmentation fault caused by QProcess::start()
From: "Marius Dalsmo"
Date: Fri, 10 Dec 2004 13:29:08 +0100
Thanks for your reponse, Girish. The reason for the statusProcess is to
execute a command that checks the status of another program every 10s. My
application is a GUI-frontend that monitors this other program.

I can't see that the statusProcess is deleted by another thread. The
statusProcess is only manipulated by the MainWindow thread.

However, using QTimer instead of running this check in a looping thread is a
good idea. I have tried this solution, and it seems to work. No segmentation
faults yet! :)

If someone have any clue why the first solution didn't work, please give me
a hint ;)

Marius



"Girish Ramakrishnan" <gramakri@xxxxxxxx> wrote in message
news:cp9sel$tc3$1@xxxxxxxxxxxxxxxxxxxxx
> Marius Dalsmo wrote:
> > Hi,
> >
> > I have a problem with a QProcess instance in my code.
> >
> > I have this class:
> > class MainWindow : public QMainWindow, public QThread
> >
> > where a QProcess object is initated and declared in the constructor:
> > statusProcess = new QProcess( this );
> > statusProcess->setArguments(QStringList::split("command"));
> >
> > The process is started from a loop that runs every 10th second. The loop
> > itself runs in a thread:
> > void MainWindow::run()
> > {
> >     while(!quit) {
> >         sleep(MAIN_LOOP_SLEEP);
> >         if (!statusProcess->isRunning()) {
> >             if (!statusProcess->start()) {
> >                 statusBar()->message("Unable to execute command");
> >             }
> >         }
> >     }
> > }
> >
> > This happends: the program works fine for about 20 minutes (the command
> > executes and exits), then a segmentation fault occurs.
> >
> > I have ran the program in gdb, which gives this output:
> > Detaching after fork from child process 21853.
> > Detaching after fork from child process 21864.
> > Detaching after fork from child process 21868.
> > Detaching after fork from child process 21870.
> > Detaching after fork from child process 21874.
> > Detaching after fork from child process 21876.
> > Program received signal SIGSEGV, Segmentation fault.
> > [Switching to Thread 1096993712 (LWP 17619)]
> > 0x402ca59e in QProcess::start () from /usr/lib/libqt.so.3
> > (gdb) bt
> > #0 0x402ca59e in QProcess::start () from /usr/lib/libqt.so.3
> > #1 0x08057bd1 in MainWindow::run (this=0xbffff080) at
main_window.cpp:515
> > #2 0x40cb0855 in QThreadInstance::start () from /usr/lib/libqt-mt.so.3
> > #3 0x411919dd in start_thread () from /lib/tls/libpthread.so.0
> > #4 0x40a44ffa in clone () from /lib/tls/libc.so.6
> > (gdb) frame 1
> > #1 0x08057bd1 in MainWindow::run (this=0xbffff080) at
main_window.cpp:515
> > Line number 515 out of range; main_window.cpp has 506 lines.
> > (gdb) print statusProcess
> > $1 = (struct QProcess *) 0x8196550
> >
> > Line number 515 in main_window.cpp is:
> > if (!statusProcess->start()) {
> >
> > Anyone that knows what to do?
> >
> > Regards
> > Marius Dalsmo
> >
> >
> >
>
> Bad guess: Would anyone be deleting statusProcess by any chance in
> another thread (the gui thread for instance)?
>
> Difficult to say anything else without the entire code. Not sure what
> you are trying to do, but wont it be easier to use a QTimer which fires
> every 10s and checks the status of the process and just restarts it if
> it has exited... If you want to restart the process immediately instead
> of 10s, just use QProcess::processExited.
>
> Girish

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>