-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils-process.stanza
More file actions
26 lines (21 loc) · 853 Bytes
/
utils-process.stanza
File metadata and controls
26 lines (21 loc) · 853 Bytes
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
;; See license.txt for details about licensing.
defpackage utils/process :
import core
import collections
#if-defined(PLATFORM-WINDOWS):
extern terminate_process: (long) -> int
public lostanza defn kill-process (p: ref<Process>) -> ref<False>:
if call-c terminate_process(p.pid) != 0:
throw(KillProcessException(new Long{p.pid}, core/windows-error-msg()))
return false
#else:
extern kill: (long, int) -> int
public lostanza defn kill-process (p: ref<Process>) -> ref<False>:
if call-c kill(p.pid, 6) != 0: ; sigabrt
throw(KillProcessException(new Long{p.pid}, core/linux-error-msg()))
return false
public defstruct KillProcessException <: Exception:
pid: Long
msg: String
defmethod print (o: OutputStream, e: KillProcessException) -> False:
print(o, "Unable to kill process %_: %_" % [pid(e), msg(e)])