ReactOS  0.4.15-dev-1070-ge1a01de
kill.c
Go to the documentation of this file.
1 /*
2  * ReactOS kill
3  * Copyright (C) 2003 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * COPYRIGHT: See COPYING in the top level directory
21  * PROJECT: ReactOS kill.exe
22  * FILE: apps/utils/kill/kill.c
23  * PURPOSE: Kill a running Process
24  * PROGRAMMER: Steven Edwards (Steven_Ed4153@yahoo.com)
25  */
26 
27 /* Thanks to David, Capser, Eric and others for the example code
28  * from the old shell.exe
29  */
30 
31 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
32 #include <windows.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 
36 int
37 ExecuteKill(char * lpPid)
38 {
40  DWORD dwProcessId;
41 
42  dwProcessId = (DWORD) atol(lpPid);
43  fprintf( stderr, "Killing PID %ld...\n",dwProcessId);
46  FALSE,
47  dwProcessId
48  );
49  if (NULL == hProcess)
50  {
51  fprintf( stderr, "Could not open the process with PID = %ld\n", dwProcessId);
52  return 0;
53  }
54  if (FALSE == TerminateProcess(
55  hProcess,
56  0
57  )
58  ) {
59  fprintf( stderr, "Could not terminate the process with PID = %ld\n", dwProcessId);
60  return 0;
61  }
63  return 0;
64 }
65 
66 int main(int argc, char *argv[])
67 {
68  char tail;
70 
71  if (argc < 2)
72  {
73  fprintf( stderr, "Usage: %s PID (Process ID) \n", argv[0] );
74  return 1;
75  }
76  tail = ExecuteKill(argv[1]);
77  return 0;
78 }
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:487
struct outqueuenode * tail
Definition: adnsresfilter.c:66
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define argv
Definition: mplay32.c:18
#define DWORD
Definition: nt_native.h:44
#define FALSE
Definition: types.h:117
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:320
int main(int argc, char *argv[])
Definition: kill.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define PROCESS_TERMINATE
Definition: pstypes.h:149
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
FILE * stderr
int ExecuteKill(char *lpPid)
Definition: kill.c:37