Hello,
I have ubuntu 20.04 OS with wxWidgets 3.0.5. I have a custom
Process class (inherits from wxProcess) with OnTerminate()
function overridden. When I kill a process associated with an
instant of MyProcess class with MyProcess::Kill(), according to
the documentation of the wxProcess::OnTerminate():
https://docs.wxwidgets.org/3.0/classwx_ ...
4cbb72a172
the OnTerminate() function should not be called. But in my case it
is. Regradless of the used terminate flag.
I want to know, if this should not happen at all - mistake is in
my code, or if this is an expected behavior. If it is, then under
which circumstances is the OnTerminate() launched, when the
process is "killed" with MyProcess::Kill().
Additinal info:
I launch the command asynchronously with wxExecute("a.out",
wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, myProcess);
The program a.out has this implementation
------------------------------------------------------------
#include <iostream>
int main(int argc, char *argv[]){
int k;
std::cout << "Narg = " << argc - 1 << std::endl;
for(k = 1; k < argc; ++k){
std::cout << argv[k] << std::endl;
}
std::cerr << "Fail";
while(true){
}
return 127;
}
------------------------------------------------Thanks,
Dalibor
Hi PB,
thank you for your prompt reply a for writing a minimal example. I do not have cmd.exe at hand, nor its code to compile and use it. If you send it to me, I can try it out in my code.
1. I could compile your code with no problems, but when launched I received this error:
An assertion failed: /usr/include/wx-3.0-unofficial/wx/strvararg.h(462): assert "(argtype & (wxFormatStringSpecifier<T>::value)) == argtype" failed in wxArgNormalizer(): format specifier doesn't match argument type
I am familiared with all the commands in the example except Log messages. Therefore, I commented out all code with them a redirected the output to stdout and stderr with std::cout and std::cerr. The code worked then. See the changed code at the end of my message.
--------------------
QUOTATION: " Dalibor, I assume if you run the linked code
verbatim except replacing "cmd" with "a.out", MyProcess::OnKill()
is still called there? "
-------------------
Yes, wxKill() is still called. See the terminal output below.
------------
QUOTATION: "Since you posted the code of the child process instead of the one calling it: Does the child process actually matter or does the issue manifest with any process?"
------------
I apologize for not sending the code invoking the wxExecute (and
my laziness). I will do my best next time. I admire, and thanks
again, that you did this instead of me.
I have tried to launch inkscape with the same result:
wxExecute("inkscape", wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER,
&m_process). Here is the terminal output, which is the same
for both a.out and inkscape, except pid and inkscape warning:
------------
TERMINAL OUTPUT FOR INKSCAPE:
Process started, pid = 4751
Going to kill the process in 3 seconds.
** (org.inkscape.Inkscape:4751): WARNING **: 18:42:52.002: Fonts
dir '/home/dalibor/.config/inkscape/fonts' does not exist and will
be ignored.
Attempting to kill the process...
Process killed.
OnTerminate(): pid = 4751, status = -15
inkscape
TERMINAL OUTPUT FOR A.OUT:
Process started, pid = 4838
Going to kill the process in 3 seconds.
Numer = 0
FailAttempting to kill the process...
Process killed.
OnTerminate(): pid = 4838, status = -15
a.out
------------
-------------------------------------
CODE:
#include <wx/wx.h>
#include <wx/process.h>
class MyProcess : public wxProcess
{
public:
wxString cmd;
void OnTerminate(int pid, int status) override
{
//wxLogMessage("OnTerminate(): pid = %d, status = %d",
pid, status);
std::cout << "OnTerminate(): pid = "<< pid
<< ", status = " << status << std::endl;
std::cout << cmd <<std::endl;
}
};
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(nullptr, wxID_ANY, "Test")
{
/*wxLog::SetActiveTarget(new wxLogTextCtrl(new
wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE |
wxTE_READONLY |
wxTE_RICH2)));*/
m_process.cmd = wxString::FromUTF8("a.out");
if ( wxExecute(m_process.cmd, wxEXEC_ASYNC |
wxEXEC_MAKE_GROUP_LEADER, &m_process) )
{
//wxLogMessage("Process started, pid = %d.",
m_process.GetPid());
std::cout << "Process started, pid = " <<
m_process.GetPid() << std::endl;
m_timer.SetOwner(this);
m_timer.StartOnce(3000);
//wxLogMessage("Going to kill the process in 3
seconds.");
std::cout << "Going to kill the process in 3
seconds." << std::endl;
}
Bind(wxEVT_TIMER, [this](wxTimerEvent&)
{
//wxLogMessage("Attempting to kill the process...");
std::cout << "Attempting to kill the
process..." << std::endl;
if ( wxProcess::Kill(m_process.GetPid()) ==
wxKILL_OK )
//wxLogMessage("Process killed.");
std::cout << "Process killed." <<
std::endl;
else
//wxLogError("Could not kill the process.");
std::cerr << "Could not kill the process."
<< std::endl;
} );
}
private:
MyProcess m_process;
wxTimer m_timer;
};
class MyApp : public wxApp
{
bool OnInit() override
{
(new MyFrame)->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
--------------------------------------------------------------
Thanks,
Dalibor
Hi PB,
I appologize for the private reply.
Thanks for your effort. You approved my doublts about the
wxProcess::Kill() function. I will wait if anyone else contrubutes
to elucidation of the problem.
Thanks,
Dalibor
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/f358b0d4-72f1-4d16-b9e6-7f832a08a5f5n%40googlegroups.com.
Hello PB,
Thank you for testing this out. I agree with the conclusion: When the process is killed successfully (return value of wxProcess::Kill() is wxKILL_OK), the OnTerminate() function is launched. Due to my experience, the conclusion can be generalized to include cmd apps as well. At least on Ubuntu.
Regards,PB--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/2ff76545-71fd-40b0-bdf2-0b8be772d8c4n%40googlegroups.com.
Thanks,
Dalibor