ExitProcess and TerminateProcess Functions

Source: Internet
Author: User

A process only provides an address space and a kernel object. Its running is reflected by the main thread in its address space. When the entry point function of the main thread returns, the process ends. The termination method of this process is the normal exit of the process, and all the thread Resources in the process can be cleared correctly. In addition to the normal launch method of this process, it is sometimes necessary to force the execution of this process or other processes in the program through code. The ExitProcess () function can be used in a thread in the process, and the operation of the process will be terminated immediately. The prototype of the ExitProcess () function is VOID ExitProcess (UINT uExitCode). The uExitCode parameter sets the exit code for the process. This function is mandatory. After the execution is complete, the process has been terminated. Therefore, no code located after it can be executed. Although the ExitProcess () function can notify the dynamic link library associated with the process at the end of the process, the execution of this function is mandatory, so that ExitProcess () functions have security risks. For example, if you have applied for a period of memory with the new operator before the program calls the ExitProcess () function, the ExitProcess () function cannot be released through the delete operator because of its mandatory nature, this causes memory leakage. Note that ExitProcess () functions are mandatory and insecure. ExitProcess () can only force the exit of this process. If you want to force the termination of other processes in a process, use TerminateProcess. Unlike ExitProcess (), after the TerminateProcess () function is executed, the terminated process will not receive any notification about program exit. That is to say, the terminated process cannot finish the work before exiting before the end of the operation. Therefore, TerminateProcess () is usually used to force the process to end only when no other method can force the process to exit. The following is a prototype of the TerminateProcess () function: BOOL TerminateProcess (HANDLE hProcess, UINT uExitCode). The hProcess and uExitCode parameters are process handles and exit codes respectively. If the process ends, you can get the handle through GetCurrentProcess. TerminateProcess () is executed asynchronously. After a call is returned, you cannot determine whether the terminated process has actually exited. If the process that calls TerminateProcess () cares about this details, you can use WaitForSingleObject () to wait for the real end of the process.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.