Terminating a Process


  1. Terminating a process has the following results:

  2.     Any remaining threads in the process are marked for termination.
  3.     Any resources allocated by the process are freed.
  4.     All kernel objects are closed.
  5.     The process code is removed from memory.
  6.     The process exit code is set.
  7.     The process object is signaled.

  8. While open handles to kernel objects are closed automatically when a process terminates, the objects themselves exist until all open handles to them are closed. Therefore, an object will remain valid after a process that is using it terminates if another process has an open handle to it.()

  9. The GetExitCodeProcess function returns the termination status of a process. While a process is executing, its termination status is STILL_ACTIVE. When a process terminates, its termination status changes from STILL_ACTIVE to the exit code of the process.GetExitCodeProcess返回进程的终止状态。进程运行时,终止状态是STILL_ACTIVE,终止时为进程的退出码)

  10. When a process terminates, the state of the process object becomes signaled, releasing any threads that had been waiting for the process to terminate. For more about synchronization, see Synchronizing Execution of Multiple Threads.(进程终止时,进程对象句柄会收到signal,其他线程可以监听该信号。)

  11. When the system is terminating a process, it does not terminate any child processes that the process has created. Terminating a process does not generate notifications for WH_CBT hook procedures.(系统终止进程时,不会终止其子进程。)

  12. Use the SetProcessShutdownParameters function to specify certain aspects of the process termination at system shutdown, such as when a process should terminate relative to the other processes in the system.SetProcessShutdownParameters设置系统关机时,可以杀死其他进程)
  13. How Processes are Terminated

  14. A process executes until one of the following events occurs:

  15.     1)Any thread of the process calls the ExitProcess function. Note that some implementation of the C run-time library (CRT) call ExitProcess if the primary thread of the process returns.(进程的任意一个线程调用ExitProcess。NOTE:某些CRT在主线程退出时调用ExitProcess)
  16.     2)The last thread of the process terminates.(进程的最后一个线程退出)
  17.     3)Any thread calls the TerminateProcess function with a handle to the process.(任意线程(进程自身或其他进程),调用TerminateProcess
  18.     4)For console processes, the default console control handler calls ExitProcess when the console receives a CTRL+C or CTRL+BREAK signal.(控制台接收到CTRL+C or CTRL+BREAK信号,调用ExitProcess
  19.     5)The user shuts down the system or logs off.(用户关机或注销)

  20. Do not terminate a process unless its threads are in known states. If a thread is waiting on a kernel object, it will not be terminated until the wait has completed. This can cause the application to stop responding.(如果线程等待内核对象,导致线程不会被杀死,直到等待结束)

  21. The primary thread can avoid terminating other threads by directing them to call ExitThread before causing the process to terminate (for more information, see Terminating a Thread). The primary thread can still call ExitProcess afterwards to ensure that all threads are terminated.(主线程调用ExitProcess保证所有线程终止)

  22. The exit code for a process is either the value specified in the call to ExitProcess or TerminateProcess, or the value returned by the main or WinMain function of the process. If a process is terminated due to a fatal exception, the exit code is the value of the exception that caused the termination. In addition, this value is used as the exit code for all the threads that were executing when the exception occurred.(返回码可以是ExitProcessTerminateProcess所设定的,可以是main函数返回的,也可以是导致进程异常终止的退出码)

  23. If a process is terminated by ExitProcess, the system calls the entry-point function of each attached DLL with a value indicating that the process is detaching from the DLL. DLLs are not notified when a process is terminated by TerminateProcess. For more information about DLLs, see Dynamic-Link Libraries.ExitProcess通知进程的DLL进程退出,TerminateProcess不做此通知)

  24. If a process is terminated by TerminateProcess, all threads of the process are terminated immediately with no chance to run additional code. This means that the thread does not execute code in termination handler blocks. In addition, no attached DLLs are notified that the process is detaching. If you need to have one process terminate another process, the following steps provide a better solution:TerminateProcess会立即终止进程,进程没有时间做其他事情。)

  25.     Have both processes call the RegisterWindowMessage function to create a private message.
  26.     One process can terminate the other process by broadcasting a private message using the BroadcastSystemMessage function as follows:

  27.         DWORD dwRecipients = BSM_APPLICATIONS;
  28.         UINT uMessage = PM_MYMSG;
  29.         WPARAM wParam = 0;
  30.         LPARAM lParam = 0;

  31.         BroadcastSystemMessage(
  32.             BSF_IGNORECURRENTTASK, // do not send message to this process
  33.             &dwRecipients, // broadcast only to applications
  34.             uMessage, // registered private message
  35.             wParam, // message-specific value
  36.             lParam ); // message-specific value

  37.     The process receiving the private message calls ExitProcess to terminate its execution.

  38. The execution of the ExitProcess, ExitThread, CreateThread, CreateRemoteThread, and CreateProcess functions is serialized within an address space. The following restrictions apply:

  39.     During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is finished for the process.
  40.     Only one thread at a time can be in a DLL initialization or detach routine.
  41.     The ExitProcess function does not return until there are no threads are in their DLL initialization or detach routines.

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(86) | 评论(0) | 转发(0) |
0

上一篇:windows关机,窗口事件

下一篇:find exec linux

给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
The Design and Implementation of the 4.4BSD Operating System Marshall Kirk McKusick Keith Bostic Michael J. Karels John S. Quarterman Copyright © 1996 Addison-Wesley Longman, Inc The second chapter of the book, The Design and Implementation of the 4.4BSD Operating System is excerpted here with the permission of the publisher. No part of it may be further reproduced or distributed without the publisher's express written permission. The rest of the book explores the concepts introduced in this chapter in incredible detail and is an excellent reference for anyone with an interest in BSD UNIX. More information about this book is available from the publisher, with whom you can also sign up to receive news of related titles. Information about BSD courses is available from Kirk McKusick. [ Split HTML / Single HTML ] Table of Contents 2 Design Overview of 4.4BSD 2.1 4.4BSD Facilities and the Kernel 2.1.1 The Kernel 2.2 Kernel Organization 2.3 Kernel Services 2.4 Process Management 2.4.1 Signals 2.4.2 Process Groups and Sessions 2.5 Memory Management 2.5.1 BSD Memory-Management Design Decisions 2.5.2 Memory Management Inside the Kernel 2.6 I/O System 2.6.1 Descriptors and I/O 2.6.2 Descriptor Management 2.6.3 Devices 2.6.4 Socket IPC 2.6.5 Scatter/Gather I/O 2.6.6 Multiple Filesystem Support 2.7 Filesystems 2.8 Filestores 2.9 Network Filesystem 2.10 Terminals 2.11 Interprocess Communication 2.12 Network Communication 2.13 Network Implementation 2.14 System Operation References List of Tables 2-1. Machine-independent software in the 4.4BSD kernel 2-2. Machine-dependent software for the HP300 in the 4.4BSD kernel List of Figures 2-1. Process lifecycle 2-2. A small filesystem Chapter 2 Design Overview of 4.4BSD 2.1 4.4BSD Facilities and the Kernel The 4.4BSD kernel provides four basic facilities: processes, a filesystem, communications, and system startup. This section outlines where each of these four basic services is described in this book. Processes constitute a t

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kelsel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值