]> git.lyx.org Git - lyx.git/blob - src/support/kill.C
MacOSX compile fix.
[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 #ifdef HAVE_SYS_TYPES_H
16 # include <sys/types.h>
17 #endif
18 #include <csignal>
19
20 #ifdef _WIN32
21 #include "debug.h"
22 #include "os.h"
23
24 #include <windows.h>
25 #include <cerrno>
26
27 using std::endl;
28 #endif //_WIN32
29
30 int lyx::support::kill(int pid, int sig)
31 {
32 #ifdef _WIN32
33         if (pid == (int)GetCurrentProcessId()) {
34                 return -(raise(sig));
35         } else {
36                 HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
37                 if (!hProcess) {
38                         lyxerr << "kill OpenProcess failed!" << endl;
39                         return -1;
40                 } else {
41                         if (!TerminateProcess(hProcess, sig)){
42                                 lyxerr << "kill process failed!" << endl;
43                                 CloseHandle(hProcess);
44                                 return -1;
45                         }
46                 CloseHandle(hProcess);
47                 }
48         }
49         return 0;
50
51 #else
52         return ::kill(pid, sig);
53 #endif
54 }