]> git.lyx.org Git - lyx.git/blob - src/support/kill.cpp
Improve quotation mark opening/closing guess
[lyx.git] / src / support / kill.cpp
1 /**
2  * \file kill.cpp
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 "support/debug.h"
22 #include "support/os.h"
23
24 #include <windows.h>
25 #include <cerrno>
26 #endif //_WIN32
27
28 namespace lyx {
29
30 int support::kill(int pid, int sig)
31 {
32 #ifdef _WIN32
33         if (pid == (int)GetCurrentProcessId())
34                 return -raise(sig);
35         HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
36         if (!hProcess) {
37                 LYXERR0("kill OpenProcess failed!");
38                 return -1;
39         }
40         if (!TerminateProcess(hProcess, sig)) {
41                 LYXERR0("kill process failed!");
42                 CloseHandle(hProcess);
43                 return -1;
44         }
45         CloseHandle(hProcess);
46         return 0;
47 #else
48         return ::kill(pid, sig);
49 #endif
50 }
51
52
53 } // namespace lyx