Bug 62517 - Cannot kill child process in KProcess destructor.
Summary: Cannot kill child process in KProcess destructor.
Status: RESOLVED NOT A BUG
Alias: None
Product: kdelibs
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Stephan Kulow
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-08-12 02:24 UTC by Gary Cramblitt
Modified: 2003-09-28 21:19 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Cramblitt 2003-08-12 02:24:42 UTC
Version:           Gideon 3.0.0a5 (using KDE KDE 3.1)
Installed from:    RedHat RPMs
OS:          Linux

I'm working on a KPart that uses KProcess to launch a child process in runmode NotifyOnExit.  I need to terminate child process with SIGTERM (not SIGKILL) if my KPart is closed/destroyed.  I cannot call KProcess->kill(SIGTERM) in the KProcess destructor (no error; simply doesn't do anything).  My guess is that KProcessController has already been destroyed by the time KProcess destructor is called.  Since my component is a KPart, I cannot hook application queryClose events, etc.  Please enhance KProcess to either:

1.  Invoke KProcess destructor before KProcessController is destroyed (assuming that is the problem), or

2.  Allow to override default SIGKILL when KProcess is destroyed with SIGTERM, or

3.  Expose an event or signal that KProcess is about to be destroyed before KProcessController is destroyed, or

4.  Expose en event or signal that KProcessController is about to be destroyed, or

5.  Enhance KParts to emit event or signal that user has requested close/destruction, ala KMainWindow::queryClose().

Option 2 might be the simplest solution, but would need to be overridable per KProcess instance.  Options 5 would be the best general-purpose solution. I can supply my source code, if needed, but it is a bit long.  Thanks.
Comment 1 Gary Cramblitt 2003-09-28 21:19:14 UTC
Resolving this bug to INVALID.  It turns out that one must call KProcess->wait() after 
calling kill(SIGTERM) in order for the child process to exit.  The following code in my 
KPart destructor solved the problem. 
 
kspeakPart::~kspeakPart() 
{ 
    kdDebug() << "kspeakPart destructor called." << endl; 
    if (m_process != NULL) 
    { 
        if (m_process->isRunning()) 
            { 
            m_process->kill(SIGTERM); 
            kdDebug() << "SIGTERM sent from kspeakPart destructor." << endl; 
            m_process->wait(2); 
            } 
         
        // When a KProcess is destroyed, it sends a SIGKILL to the child process. 
        // In our case, that won't stop speaking, because the signal handler in 
speakfile 
        // won't get a chance to signal the grandchild processes. 
        delete m_process; 
        m_process = NULL; 
    } 
}