I am doing to following:
gdb -p $progid -x $file
>> cat file
>> handle SIGUSR1 nostop
c
How can I handle all signals to nostop without having to write:
handle SIGUSR1 nostop
handle SIGUSR2 nostop
Etc...
handle all nostop
Further documentation: here.
Related
I want to get the stderr of a QProcess (ideally as a QIODevice), but I can't figure out how. Another thread is reading from stdout using the methods QProcess inherits from QIODevice, so QProcess::MergedChannels and QProcess::setReadChannel(...) are out of the question. QProcess::readAllStandardError() is also not ideal.
You have to connect some slot to readyReadStandardError() signal of QProcess to read data by QProcess::readAllStandardError() and be store it for concatenation, in addition to finished() signal to make concluding calls, similar to how you would do that for standard output.
connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readErrData()));
connect(&process, SIGNAL(finished(int , QProcess::ExitStatus)),
this, SLOT(finalizeProcessTask(int , QProcess::ExitStatus)));
I'm writing a console multi-process application in c++ using WinAPI. So I have the Dispatcher(e.g. "Parent") and the Client(e.g. "Child") processes. Both processes are synchronized: they're using semaphors, events, mutexes and the pipe (all of them are standard WinAPI handles). Application stop when the user type the "exit" command. If the user do so, the dispatcher process notifies it's child, and then child releases its resources and makes another before-exit procedures to exit correctly. But there's a thing that bothers me: what will happen if the user press the window "close" button? If so, I should listen to close event and then perform my resource-releasing procedure. What is the easiest way to handle window close event?
Write a console handler routine that detects CTRL_CLOSE_EVENT (and CTRL_C_EVENT, if desired), and use SetConsoleCtrlHandler to add the handler routine to your process.
It isn't really different from the client process crashing or being terminated through Task Manager. You ought to be resilient to that as well. The ultimate signal you get for that in the parent process is that the client's process handle will be signaled.
Use WaitForMultipleObjects, along with those other handles, to detect this.
I'm writing a GUI application for Windows using MFC and C++.
So I need to send messages to my MAIN thread from my worker thread to tell it to update my GUI. However I'm not sure how to send a message to the actual MAIN thread rather than a Window. As it is I can see it is in the MAIN thread when it receives the message but I am not sure if this is guaranteed or just luck.
In worker:
PostMessage( *myTestToolDlg, WM_YOU_HAVE_DATA,UPDATE_GUI, 0 );
In application window:
LRESULT CTestToolDlg::OnData(WPARAM wp, LPARAM )
Does this somehow mean that?
You can get your main thread's thread id by using something like threadId = GetCurrentThreadId(); in the main thread, and then send a message to it by calling PostThreadMessage(threadId, ...) from your worker thread.
However, as Hans Passant said -> here <-, you should avoid using PostThreadMessage to send messages to UI threads, and should better send messages to its window.
If you want to modify a ListBox or ListView directly, you can use SendDlgItemMessageA()
Example :
char const* pChar = "My text to be updated";
SendDlgItemMessageA(hWindow, IDC_LISTBOX, LB_DELETESTRING, 0, 0);
SendDlgItemMessageA(hWindow, IDC_LISTBOX, LB_INSERTSTRING, -1, (LPARAM)pChar);
SIGINT is used to handle Ctrl+c but there is no signal for Ctrl+n and Ctrl+d, how can I handle these? Any idea?
I have a link list in my program and I have to perform some link list operations in these signal handlers. I just want to detect Ctrl+d and Ctrl+n in the normal flow of program.
I am trying to create a child process and then send SIGINT to the child without terminating the parent. I tried this:
pid=fork();
if (!pid)
{
setpgrp();
cout<<"waiting...\n";
while(1);
}
else
{
cout<<"parent";
wait(NULL);
}
but when I hit C-c both process were terminated
Don't use CTRL-C, this sends a signal to all processes with the same controlling terminal (ie, in the same session). That's something that setpgid doesn't change though I think there's a setsid (set session ID) call for that purpose.
The easiest solution is simply to target the specific process rather than a session. From the command line:
kill -INT pid
From C:
kill (pid, SIGINT);
where pid is the process ID you want to send the signal to.
The parent can get the relevant PID from the return value from fork(). If a child wants its own PID, it can call getpid().
Aha, the mystery of process groups and sessions and process group leaders and session group leaders appears again.
Your control/C sent the signal to a group. You need to signal an individual pid, so follow paxdiablo's instructions or signal ("kill") the child from the parent. And don't busy wait! Put a sleep(1) in the loop, or better yet, one of the wait(2) system calls.
You could try implementing a SIGINT signal handler which, if a child process is running, kills the child process (and if not, shuts down the application).
Alternatively, set the parent's SIGINT handler to SIG_IGN and the child's to SIG_DFL.