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. CapsLock indicator on Ubuntu for Thinkpad

    http://askubuntu.com/questions/292535/how-to-get-caps-num-scroll-lock-keys-osd-notification sudo add ...

  2. Mina笔记

    1.MINA框架简介 MINA(Multipurpose Infrastructure for Network Applications)是用于开发高性能和高可用性的网络应用程序的基础框架.通过使用M ...

  3. 修改上一篇文章的node.js代码,支持默认页及支持中文

    服务端 app.js var app = require('http').createServer(handler) var io = require('socket.io')(app); var f ...

  4. AFNetworking (3.1.0) 源码解析 <三>

    今天要介绍的是Reachability文件夹下的AFNetworkReachabilityManager类.通过字面意思我们就可以知道AFNetworkReachabilityManager是用来监测 ...

  5. SKEmitterNode类

    继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架  /System/L ...

  6. Activity进入与退出的动画

    1.在res建立目录anim放入动画效果xml文件 1.1   进入文件  push_left_in.xml <?xml version="1.0" encoding=&qu ...

  7. 真正菜鸟用教程之WQSG Scrip Export WQSG (脚本导出导入工具,PSP、NDS汉化必备 )

    先扫盲WQSG是干什么用的 一些掌机类游戏汉化比方PSP NDS 汉化必备之物 它能够依据字典转换文本 假设你不知道这是啥玩意,快去充电染成茜色的坂道 文本提取(导出)方法 (下文称导出文章) 在导出 ...

  8. Understand Rails Authenticity Token

    翻译整理自: http://stackoverflow.com/questions/941594/understand-rails-authenticity-token 主要翻译的是第一个回答,另外结 ...

  9. 学做酷炫有爱的免费网页,学习 Github Page 教你分分钟搭建自己的博客

    Github Page 网页搭建教程,教你分分钟搭建自己的博客 很多其它美丽的网页搭建教程教程.请看这里:http://www.duobei.com/course/8506331668 waterma ...

  10. easyui 给文本框 checkbox赋值问题

    刚进公司 要做一个后台维护系统,选择easyui 从未接触过 对于页面给文本框赋值遇到一些问题 写下了来 我之前使用了好几种方式都未能成功给input 文本框赋值 第一尝试传统的JavaScript代 ...