summary refs log tree commit diff stats
path: root/nimsuggest/procmonitor.nim
diff options
context:
space:
mode:
Diffstat (limited to 'nimsuggest/procmonitor.nim')
-rw-r--r--nimsuggest/procmonitor.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/nimsuggest/procmonitor.nim b/nimsuggest/procmonitor.nim
new file mode 100644
index 000000000..0f1ba1e0d
--- /dev/null
+++ b/nimsuggest/procmonitor.nim
@@ -0,0 +1,34 @@
+# Monitor a client process and shutdown the current process, if the client
+# process is found to be dead
+
+import os
+
+when defined(posix):
+  import posix_utils
+  import posix
+
+when defined(windows):
+  import winlean
+
+when defined(posix):
+  proc monitorClientProcessIdThreadProc(pid: int) {.thread.} =
+    while true:
+      sleep(1000)
+      try:
+        sendSignal(Pid(pid), 0)
+      except:
+        discard kill(Pid(getCurrentProcessId()), cint(SIGTERM))
+
+when defined(windows):
+  proc monitorClientProcessIdThreadProc(pid: int) {.thread.} =
+    var process = openProcess(SYNCHRONIZE, 0, DWORD(pid))
+    if process != 0:
+      discard waitForSingleObject(process, INFINITE)
+      discard closeHandle(process)
+    quit(0)
+
+var tid: Thread[int]
+
+proc hookProcMonitor*(pid: int) =
+  when defined(posix) or defined(windows):
+    createThread(tid, monitorClientProcessIdThreadProc, pid)
div class='alt'>
ac07e589 ^



e0610e39 ^
ac07e589 ^

608a7fa8 ^
































e4ac3c9e ^
608a7fa8 ^
14a38052 ^
c56d803c ^

ebd35521 ^

c56d803c ^









608a7fa8 ^
52daf072 ^
14a38052 ^


d1c9392a ^
14a38052 ^
ac07e589 ^
14a38052 ^

ac07e589 ^
14a38052 ^
08a0eed6 ^
14a38052 ^
ac07e589 ^
d1c9392a ^
14a38052 ^
ac07e589 ^
14a38052 ^

d1c9392a ^
901ae474 ^
14a38052 ^
ac07e589 ^
14a38052 ^

52daf072 ^
14a38052 ^
9309600c ^

ac07e589 ^
52daf072 ^
14a38052 ^
220ac389 ^
14a38052 ^
52daf072 ^
14a38052 ^
52daf072 ^

14a38052 ^

d1c9392a ^
14a38052 ^
608a7fa8 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120