Kill Process by Name
(works in: Microsoft Windows 95/98/ME/NT/2000/XP)
It is sometimes necessary to terminate a running process in MS-Windows. The Win32 API provides the TerminateProcess function for this, but it requires a "handle to the process". In many cases it is not apparent how to get this handle if all you know is the process name. The following routine lets you get around this problem.

The routine is named KILL_PROC_BY_NAME, and is available as part of the C++ source file EXAM28.CPP. The routine has the following calling parameters:

int KILL_PROC_BY_NAME(const char *)
where the process name is supplied as a zero-terminated C char string and it returns an integer completion code.
You can download the file in ZIP format by clicking on the following link.

Download Exam28.zip (3 kB, last modified: 3/10/2002)
This works for Microsoft Windows 95/98/ME/NT/2000/XP. I have tested with Visual C++ v6.0 but it should work with other versions also. Please let me know of exceptions.

After downloading, unzip the file Exam28.cpp into any folder. It contains a short console mode program which demonstrates how to call KILL_PROC_BY_NAME to terminate the NotePad program.

Change history:

3/10/2002 - Fixed memory leaks as suggested by Jonathan Richard-Brochu and also made Borland C compatible as suggested by Bob Christensen.
Note: This routine uses the Windows API function TerminateProcess to terminate the process. This may not be suitable for all purposes. In particular, note the following remarks from the MSDN description of TerminateProcess.

Remarks (on TerminateProcess)

The TerminateProcess function is used to unconditionally cause a process
to exit. Use it only in extreme circumstances. The state of global data
maintained by dynamic-link libraries (DLLs) may be compromised if
TerminateProcess is used rather than ExitProcess.

TerminateProcess causes all threads within a process to terminate,
and causes a process to exit, but DLLs attached to the process are not
notified that the process is terminating.

Terminating a process causes the following:

1. All of the object handles opened by the process are closed.

2. All of the threads in the process terminate their execution.

3. The state of the process object becomes signaled, satisfying any
threads that had been waiting for the process to terminate.

4. The states of all threads of the process become signaled, satisfying
any threads that had been waiting for the threads to terminate.

5. The termination status of the process changes from STILL_ACTIVE to
the exit value of the process.

Terminating a process does not cause child processes to be terminated.

Terminating a process does not necessarily remove the process object
from the system. A process object is deleted when the last handle to the
process is closed.
If you have any questions please send them to the e-mail address below.

Further Reading:

Howto Enumerate Applications in Win32 (Microsoft KB article)

Disclaimer:
This site contains some software that I've written over the years. It is believed to work, but there is no warranty. Please use at your own risk. If you notice any bugs please let me know by email at kochhar@physiology.wisc.edu.

Return to Ravi's Free Software Page
Return to Ravi's Home Page
Back to The Basement
This page last modified on : Mar. 10, 2002

http://www.physiology.wisc.edu/ravi/software/killproc/

Kill Process by Name的更多相关文章

  1. linux 终端报错 Out of memory: Kill process[PID] [process name] score问题分析

    从Out of memory来看是内存超出了,后面的 Kill process[PID] [process name] score好像和进程有关了,下面我们就一起来看看linux 终端报错 Out o ...

  2. Mongodb副本集--Out of memory: Kill process 37325 (mongod)

    1.Mongodb副本集--Out of memory: Kill process 37325 (mongod) 场景描述: 恢复一个22TB数据的mongodb实例的时候. 将备用结点加入mongo ...

  3. 理解和配置Out of memory: Kill process

    转自:爱开源 理解 OOM killer 最近有位 VPS 客户抱怨 MySQL 无缘无故挂掉,还有位客户抱怨 VPS 经常死机,登陆到终端看了一下,都是常见的 Out of memory 问题.这通 ...

  4. Out of memory: Kill process 内存不足

    服务直接被 killed,感觉特别奇怪.代码肯定是没有问题的,但为什么放到服务器上就出错了呢. 部署时报错如下: Failed to add the deployment content to the ...

  5. Android Kill Process

    /********************************************************************** * Android Kill Process * 说明: ...

  6. Out of memory: Kill process 6033 (mysqld) score 85 or sacrifice child

    进入正题前先说明:OOM killer什么时候出现? linux下允许程序申请比系统可用内存更多的内存,这个特性叫Overcommit.这样做是出于优化系统考虑,因为不是所有的程序申请了内存就立刻使用 ...

  7. [LeetCode] Kill Process 结束进程

    Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...

  8. 582. Kill Process杀死所有子代

    [抄题]: Given n processes, each process has a unique PID (process id) and its PPID (parent process id) ...

  9. LeetCode Kill Process

    原题链接在这里:https://leetcode.com/problems/kill-process/description/ 题目: Given n processes, each process ...

随机推荐

  1. java常用包

    java的核心类都放在java这个包以及其子包下,java扩展的许多类都放在javax包以及其子包下.这些实用类也就是平时经常说的API(应用程序接口). 以下几个是java语言中常用包 java.l ...

  2. Mac下phpstorm 浏览器出现 502 bad gateway 解决办法

    问题: 在网上搜了好久,都没有合适的解决办法,于是决定分享下自己鼓捣好久解决了的办法,希望能帮到大家. 出现上述情况,一般在phpstorm里都会出现这个提示 我们只需要点击蓝色的进去,或者点phps ...

  3. Winform Textbox实现滚动条始终在最下面

    在用textbox时,实现一些信息追加时,要使滚动条始终呆在最下面的实现方法. 以textbox1为例,事件TextChanged中执行以下代码即可 private void textBox1_Tex ...

  4. linux开关机命令

    1.reboot重启 2.shutdown -r now 立即重启 root用户使用,与reboot命令相同 3.shutdown -r 10 过10分钟后重启root用户使用 4.shutdown ...

  5. Dev GridControl 按条件合并相同单元格

    Dev 默认的合并方式,只要(垂直方向)相邻两个单元格的值相同都会进行合并,这种方式并不是最优的,所以需要在进行合并的过程中进行判断. 方式如下: 1:先设置需要合并的列为允许合并 OptionsVi ...

  6. sql数据库之间数据的转录

    private void Form1_Load(object sender, EventArgs e) { BindDataBase(combDataBaseNew, , ""); ...

  7. 《CSS网站布局实录》学习笔记(六)

    第六章 CSS高级应用与技巧 6.1 id与class 6.1.1 什么是id id是XHTML元素的一个属性,用于标识对象名称.无论是class还是id,都是XHTML所支持的公共属性,并且也是其核 ...

  8. 关于android:screenOrientation="portrait"等

    1.android:screenOrientation="portrait",表示当切换横竖屏的时候,屏幕的内容始终以竖屏显示,而不会根据屏幕的方向来显示内容. 2.插入个Andr ...

  9. JS时间的计算,当前日期加一天或者几天的计算

    //alert();//debugger;var newriqi="";var jjd=defaultForm.getCellById(sjyxjid).getText();var ...

  10. 第一次启动MySQL时报错

    [root@localhost~]#/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mys ...