Solved

Kill a process with the pid.

Posted on 1999-01-28
3
720 Views
Last Modified: 2008-02-01
I know the pid of a process that I want to kill.  How I can do it on Windows NT? I haven´t found the kill function or its equivalent.
0
Comment
Question by:riclueje
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
_Scotch_ earned 50 total points
ID: 1258473
If the target process is cooperative you can send it a message
like WM_QUIT or something.  Otherwise I'd look at:

OpenProcess()
TerminateProcess()
CloseProcess()
0
 

Author Comment

by:riclueje
ID: 1258474
Thanks, but I only know the process's pid.  I use de spawnl function that return the process's pid and I need to kill the process started with the spawnl funtion.  
0
 
LVL 3

Expert Comment

by:_Scotch_
ID: 1258475
Right... You do it this way:

HANDLE aHandle = OpenProcess(PROCESS_TERMINATE, FALSE, proc-id);
int aStatus = TerminateProcess(aHandle, desired-exit-code);
if (!aStatus)  {
    char s[80];
    sprintf(s, "TerminateProcess() failed, code: %d", aStatus);
    AfxMessageBox(s);
    }
CloseHandle(aHandle);

Sorry about the typo before... CloseHandle() should be used to
free the handle, not CloseProcess()...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now