Solved

Kill a process with the pid.

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
C Programming - If Statement 8 84
Please explain C language error codes ? 5 52
MySQL recovery 7 59
Exchange 2013 fills up C drive with logs 4 29
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 use strings and some functions related to them in the C programming language.

739 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