]> git.lyx.org Git - lyx.git/blob - src/support/kill.C
make "make distcheck" work
[lyx.git] / src / support / kill.C
1 /**
2  * \file kill.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/lyxlib.h"
14
15 #include <sys/types.h>
16 #include <csignal>
17
18 #ifdef _WIN32
19 #include "debug.h"
20 #include "os.h"
21
22 #include <windows.h>
23 #include <errno.h>
24
25 using std::endl;
26 #endif //_WIN32
27
28 int lyx::support::kill(int pid, int sig)
29 {
30 #ifdef _WIN32
31         if (pid == (int)GetCurrentProcessId()) {
32                 return -(raise(sig));
33         } else {
34                 HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
35                 if (!hProcess) {
36                         lyxerr << "kill OpenProcess failed!" << endl;
37                         return -1;
38                 } else {
39                         if (!TerminateProcess(hProcess, sig)){
40                                 lyxerr << "kill process failed!" << endl;
41                                 CloseHandle(hProcess);
42                                 return -1;
43                         }
44                 CloseHandle(hProcess);
45                 }
46         }
47         return 0;
48
49 #else
50         return ::kill(pid, sig);
51 #endif
52 }