Solved

Kill a process with the pid.

Posted on 1999-01-28
3
724 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to design, and implement simple interface 5 135
Problem to ASCII 1 183
What is sub-make ? 2 61
Test the speeds on my PC Drives 12 48
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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

803 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