Kill Process by Name
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的更多相关文章
- linux 终端报错 Out of memory: Kill process[PID] [process name] score问题分析
从Out of memory来看是内存超出了,后面的 Kill process[PID] [process name] score好像和进程有关了,下面我们就一起来看看linux 终端报错 Out o ...
- Mongodb副本集--Out of memory: Kill process 37325 (mongod)
1.Mongodb副本集--Out of memory: Kill process 37325 (mongod) 场景描述: 恢复一个22TB数据的mongodb实例的时候. 将备用结点加入mongo ...
- 理解和配置Out of memory: Kill process
转自:爱开源 理解 OOM killer 最近有位 VPS 客户抱怨 MySQL 无缘无故挂掉,还有位客户抱怨 VPS 经常死机,登陆到终端看了一下,都是常见的 Out of memory 问题.这通 ...
- Out of memory: Kill process 内存不足
服务直接被 killed,感觉特别奇怪.代码肯定是没有问题的,但为什么放到服务器上就出错了呢. 部署时报错如下: Failed to add the deployment content to the ...
- Android Kill Process
/********************************************************************** * Android Kill Process * 说明: ...
- Out of memory: Kill process 6033 (mysqld) score 85 or sacrifice child
进入正题前先说明:OOM killer什么时候出现? linux下允许程序申请比系统可用内存更多的内存,这个特性叫Overcommit.这样做是出于优化系统考虑,因为不是所有的程序申请了内存就立刻使用 ...
- [LeetCode] Kill Process 结束进程
Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...
- 582. Kill Process杀死所有子代
[抄题]: Given n processes, each process has a unique PID (process id) and its PPID (parent process id) ...
- LeetCode Kill Process
原题链接在这里:https://leetcode.com/problems/kill-process/description/ 题目: Given n processes, each process ...
随机推荐
- C++ —— 非常量引用不能指向临时对象
目录 举例 分析 解决 1.举例 非常量引用 指向 临时对象 —— 即:将 临时对象 传递给 非常量引用类型. 如以下情况就会出现: 实现实数Rational类,实数可以使用+号相加,运算的结果要可以 ...
- GDB错误:Cannot find bounds of current function
http://blog.csdn.net/zoomdy/article/details/17249165 mingdu.zheng <at> gmail <dot> com 使 ...
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
- 【前端JS】input textarea 默认文字,点击消失
如题.前端页面的 input textarea 有时候须要显示默认文字以提示用户,下面为实现代码,以 input 为例.textarea 能够直接搬用 HTML <input type=&quo ...
- Linux/UNIX套接字连接
套接字连接 套接字是一种通信机子.凭借这样的机制.客户/server系统的开发工作既能够在本地单机上进行.也能够夸网络进行. 套接字的创建和使用与管道是有差别的.由于套接字明白地将客户和server区 ...
- 1629 - Cake slicing(DP)
花了近2个小时终于AC,好爽.. 一道类似于最优矩阵链乘的题目,受<切木棍>那道题的启示,该题的原理也是一样的,仅仅只是变成了且面积.那么对应的也要添加维度 . 显然要完整的表示状态,最少 ...
- Android(java)学习笔记253:ContentProvider使用之内容观察者02
下面通过3个应用程序之间的交互说明一下内容观察者: 一. 如下3个应用程序为相互交互的: 二.交互逻辑图: 三.具体代码: 1. 16_数据库工程: (1)数据库帮助类BankDBOpenHelp ...
- Jquery插件-Html5图片上传并裁剪
/** * 图片裁剪 * @author yanglizhe * 2015/11/16 */ (function($){ /** * Drag */ var Drag={obj:null,init:f ...
- 从BufferedImage到InputStream,实现绘图后进行下载(生成二维码图片并下载)
@SuppressWarnings("resource") public void download() throws Exception{ String filename = & ...
- HTTPS 部署简要指南
许多Web开发者都知道SSL,但常见的情况是SSL没有完整地部署或者没有部署在它应该部署的地方.这篇关于何时及如何部署SSL的简要指南,将帮助你避免大多数常见错误. 要点 如果你有任何机密信息,或者你 ...