SIGKILL
on Unix/Linux or via TerminateProcess()
on Windows, the process dies immediately and there is no way for that process to do anything about it!SIGKILL
signal, the SIGTERM
signal can be caught and handled by the application. Similarly, on the Windows platform, when a GUI application receives a WM_CLOSE
message, it can react to that message. In both cases, the application is supposed to quit ASAP, but can do some "clean up" work before terminating.Ok, thank you. but can i then prevent a user from killing the process manually, so that it cannot be killed via taskmgr, such as intercept TerminateProcess(), if not how can it be possible that theres f.ex malware out there, which cannot be closed that easy? |
TerminateProcess()
on process #B (or sends signal SIGKILL
), then process #B has no chance to react. It just dies immediately.in windows you would catch a message (on exit or some such) and put your final send in the handler. I do not know what other OS need there, but it could vary from simply doing it before the end of main to needing a similar event handler message. |
WM_CLOSE
message to its top-level window. If, instead, your process is terminated the "hard" way, e.g. via TerminateProcess()
, then you don't get any notification message beforehand; also no atexit()
handlers will be executed.
WSADuplicateSocketW() ... The WSADuplicateSocket function is used to enable socket sharing between processes. A source process calls WSADuplicateSocket to obtain a special WSAPROTOCOL_INFO structure. It uses some interprocess communications (IPC) mechanism to pass the contents of this structure to a target process, which in turn uses it in a call to WSASocket to obtain a descriptor for the duplicated socket. ... Shared sockets are typically used to having one process that is responsible for creating sockets and establishing connections, and other processes that are responsible for information exchange. ... The underlying socket, however, will remain open until closesocket is called by the last remaining descriptor. https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaduplicatesocketw |