Home > OS >  How Windows before the process is killed by the task manager to do some processing
How Windows before the process is killed by the task manager to do some processing

Time:10-13

Run into a more depressed, I have a process, the runtime dynamically allocated the 1-4 process (these processes have no source, immutable), in my main process was killed by the task manager, to ensure that the child was killed at the same time, I realized through signal mechanism at first, later found by semaphore cannot capture the end of the process in task manager semaphore, then know that this is achieved by the TerminateProcess, so now the thought of the method is to hook the TerminateProcess before system call TerminateProcess, through the process of communication between, and I in the main process to create a thread to interact, thread after receiving the message, to kill the child, and then tell the hook function, already ok, now hook function calls the TerminateProcess function of the system, and close the main process,
Don't know if you have what good method, I think it is very trouble, but can't think of another good way to,

CodePudding user response:

Can not be in their own WM_CLOSE handled? Should be receiving this message

CodePudding user response:

reference 1/f, zara's reply:
can not be in their own WM_CLOSE handled? Should be receiving this message

No window is not in the form of GUI and closed by a task manager, want to do some processing before the process is killed, but under Windows do not know to have what good way to capture the signal

CodePudding user response:

The CONSOLE type program, also should have corresponding mechanism, reference this page http://bbs.pediy.com/archive/index.php? T - 45183. The HTML final sample? Should be acceptable to CTRL_CLOSE_EVENT notice,

CodePudding user response:

You said hook TerminateProcess is not reliable, even if must adjust the function to the end of the process, but any application can adjust the function, you simply hook the TerminateProcess task manager doesn't work, for example the somebody else can use xuetr, NORTON task manager, procexp etc., in the 3 ring, it's hard to do a global function hook, of course the client, you will run the program, the other said,

Is the right thing to you to give the child to attach a DLL (exe or modify code), the DLL's content is very simple, is the heartbeat and the main process, don't get over yourself, since you can write to the task manager hooks, show up the DLL technology you already have, mainly is a question of your thoughts,

CodePudding user response:

  • Related