Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:23:57+00:00 2026-05-25T21:23:57+00:00

In Linux/Qt I have a GUI application. The GUI starts up additional child processes

  • 0

In Linux/Qt I have a GUI application. The GUI starts up additional child processes using QProcess. To close the child processes I use QProcess::close().

Does QProcess::close() raise the unix SIGTERM signal for the child process?

(I have linked to the Qt documentation for QProcess and close() because I can not tell from the documentation if a unix signal is raised…)

UPDATE: changed question to ask about a specific unix signal: SIGTERM.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:23:58+00:00Added an answer on May 25, 2026 at 9:23 pm

    Today I found out that QProcess::close() does not raise the SIGTERM signal. To debug this issue I am capturing the stderr and stdout of the child process. Spoiler: QProcess::terminate() does raise the SIGTERM signal.


    Child process code to handle unix SIGTERM signal:

    static void unixSignalHandler(int signum) {
        qDebug("DBG: main.cpp::unixSignalHandler(). signal = %s\n", strsignal(signum));
    
        /*
         * Make sure your Qt application gracefully quits.
         * NOTE - purpose for calling qApp->exit(0):
         *      1. Forces the Qt framework's "main event loop `qApp->exec()`" to quit looping.
         *      2. Also emits the QCoreApplication::aboutToQuit() signal. This signal is used for cleanup code.
         */
        qApp->exit(0);
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        MAINOBJECT mainobject;
    
        /*
         * Setup UNIX signal handlers for some of the common signals.
         * NOTE common signals:
         *      SIGINT:     The user started the process on the command line and user ctrl-C.
         *      SIGTERM:    The user kills the process using the `kill` command.
         *                  OR
         *                  The process is started using QProcess and SIGTERM is
         *                  issued when QProcess::close() is used to close the process.
         */
        if (signal(SIGINT, unixSignalHandler) == SIG_ERR) {
            qFatal("ERR - %s(%d): An error occurred while setting a signal handler.\n", __FILE__,__LINE__);
        }
        if (signal(SIGTERM, unixSignalHandler) == SIG_ERR) {
            qFatal("ERR - %s(%d): An error occurred while setting a signal handler.\n", __FILE__,__LINE__);
        }
        // executes mainbobject.cleanupSlot() when the Qt framework emits aboutToQuit() signal.
        QObject::connect(qApp,          SIGNAL(aboutToQuit()),
                         &mainobject,   SLOT(cleanupSlot()));
    
        return a.exec();
    }
    

    Parent process code that handles close() or terminate() of the child:

    if(this->childProcess1!=NULL && this->childProcess1->state()==QProcess::Running) {
        this->childProcess1->terminate(); // raise unix SIGTERM signal on the process (let's it execute cleanup code)
        if(childProcess1->waitForFinished() == false) {
            qDebug("DBG - MainWindow::close(): Failed to close childProcess1.");
            qDebug() << "DBG - childProcess1->exitCode     =" << childProcess1->exitCode();
            qDebug() << "DBG - childProcess1->ExitStatus   =" << childProcess1->exitStatus();
            qDebug() << "DBG - childProcess1->error()      =" << childProcess1->error();
            qDebug() << "DBG - childProcess1->errorString()=" << childProcess1->errorString();
        }
    }
    if(this->childProcess2!=NULL && this->childProcess2->state()== QProcess::Running) {
        this->childProcess2->terminate(); // raise unix SIGTERM signal on the process (let's it execute cleanup code)
        if(childProcess2->waitForFinished() == false) {
            qDebug("DBG - MainWindow::close(): Failed to close childProcess2.");
            qDebug() << "DBG - childProcess2->exitCode     =" << childProcess2->exitCode();
            qDebug() << "DBG - childProcess2->ExitStatus   =" << childProcess2->exitStatus();
            qDebug() << "DBG - childProcess2->error()      =" << childProcess2->error();
            qDebug() << "DBG - childProcess2->errorString()=" << childProcess2->errorString();
        }
    }
    

    When the parent uses QProcess::terminate(), the child process output is:

    "DBG: main.cpp::unixSignalHandler(). signal = Terminated
    

    When the parent uses `QProcess::close(), the child process output is:

    DBG - PARENTOBJECT::close(): Failed to close childProcess.
    DBG - childProcess->exitCode     = 0 
    DBG - childProcess->ExitStatus   = 1 
    DBG - childProcess->error()      = 1 
    DBG - childProcess->errorString()= "Unknown error" 
    

    The output from the terminate() experiment proves that the child process is getting a SIGTERM signal.

    The output from the close() experiment proves that the child process is not getting the SIGTERM signal.


    Conclusion:

    If you want to send the child process the SIGTERM signal, use QProcess::terminate().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Linux application that makes use of OpenSSL's Python bindings and I
I have written a Java GUI using SWT. I package the application using an
I have a large GUI project that I'd like to port to Linux. What
How do Window's programmers profile their native C++ code? On Unix/Linux you have gprof
We have a Linux server application that is comprised of a number of open-source
I've been trying to use Java's ProcessBuilder to launch an application in Linux that
I have a Qt desktop application that works on Linux and Windows. At some
I have a console daemon that is run by a GUI application. When the
I have a kiosk GUI application I'm working on and it requires me to
I have Swing Java application manifesting an error on linux, which I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.