Solved

Kill a process with the pid.

Posted on 1999-01-28
3
728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

636 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