Results 1 to 20 of 23

Thread: QtService: Segfault after fork

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtService: Segfault after fork

    Do the examples bundled with QtService work properly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QtService: Segfault after fork

    This seems to be a static intitialization/race condition problem in Qt 4.7.4:
    • Sometimes after I re-compile the problem goes away (this is also probably the cause why adding/removing QtGui has any effect)
    • The problem goes away when I use Qt 4.7.4 compiled without glib
    • It also goes away when I use Qt 4.8.0, which had some QThread race conditions fixed

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtService: Segfault after fork

    Do the examples work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QtService: Segfault after fork

    The http server example shows the same behaviour.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtService: Segfault after fork

    In that case indeed the problem might be with Qt or Glib.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Oct 2007
    Posts
    11
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtService: Segfault after fork

    The similar problem also affects me on Ubuntu 11.10 64 bit factory Qt 4.7.4 installed.

    I would welcome any recommeddations about how should I create a Linux service using Qt with or without QtService.
    Thanks!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtService: Segfault after fork

    With Linux it is easy since you don't need any extra treatment in the process itself to make it a daemon. The whole work is done by the init script. If you really want, you can just fork() the process to detach it from the terminal (see man daemon for more details).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: QtService: Segfault after fork

    I have attempted to use the Linux API "daemon" to implement my application as a daemon. While the application runs to some extent, and can be viewed in the system manager, some of my custom threads do not seem to work.
    These include an SNMP thread which makes a connection to the SNMP daemon, a TCP socket thread, etc. There are other threads which do seem to work This is for a 4.8 build dynamically linked.

    Is there any particular issue with having a multithreaded Qt application work as a daemon, and specifically network related threads.

    I was going to try the heavier weight QtService to see if it provides a solution.

    In my application, I need to act as a daemon by default, but as a simple console application based on a command line argument.

    Anyone have any thoughts or experience with either of these implementations?

  9. #9
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Re: QtService: Segfault after fork

    Some additional testing has revealed that none of my secondary threads run when my application is run as a daemon using the Linux "daemon" command (e.g. daemon(0, 0)), but execute without issue when the application is run as a console application. This application is a pure console application without any GUI, and uses only the Qt Core and Qt Networking libraries (version 4.8).

    Is anyone aware of Qt secondary thread issues when using the Linux daemon command? Are there any workarounds?

    It there any reason to believe that implementing a solution basd on QtService would fair any better?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtService: Segfault after fork

    Using daemon() has nothing to do with your threads. If your threads fail to work then it's likely because you're using some relative paths or something similar in your app.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtService: Segfault after fork

    Thanks for you input. These secondary threads do not have any file system path content or issues that I am aware of. I have these secondary threads working now, and it required that the "daemon" call occur in main.cpp prior to the creation of the application object. Perhaps there is an explaination for this behavior.

  12. #12
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: QtService: Segfault after fork

    To strike a finer point on this issue, I have narrowed the problem down to a routine that I composed to detect currently running processes by process name to ensure that my application is run as a singleton.

    This routine utilizes the QProcess() Qt class and invokes "pidof" to obtain a list of PIDs for a particular process name.

    This appears to be problematic if invoked prior to the daemon() API call.

    I am not sure why, but these are my observations under Qt 4.8 with dynamic linking.

Similar Threads

  1. How to use QtService class with Qt 4.7.4
    By Qting in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2012, 11:42
  2. Replies: 1
    Last Post: 6th September 2011, 07:34
  3. gui and fork()
    By msh in forum Newbie
    Replies: 3
    Last Post: 7th January 2008, 23:08
  4. Detaching after fork from child process
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2007, 09:56
  5. how to create resource fork & data fork
    By jyoti in forum General Discussion
    Replies: 4
    Last Post: 28th November 2006, 17:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.