[os2/process]: Implement process_kill

This commit is contained in:
flysand7
2024-07-14 15:59:18 +11:00
parent 4eca60946c
commit b7ccfed9af
2 changed files with 19 additions and 42 deletions
+10 -40
View File
@@ -26,11 +26,11 @@ args := get_args()
typically is the path to the currently running executable.
*/
get_args :: proc() -> []string {
args := make([]string, len(runtime.args__), allocator = context.allocator)
result := make([]string, len(runtime.args__), allocator = context.allocator)
for rt_arg, i in runtime.args__ {
args[i] = cast(string) rt_arg
result[i] = cast(string) rt_arg
}
return args[:]
return result[:]
}
/*
@@ -387,42 +387,12 @@ process_close :: proc(process: Process) -> (Error) {
return _process_close(process)
}
// Process_Attributes :: struct {
// dir: string,
// env: []string,
// files: []^File,
// sys: ^Process_Attributes_OS_Specific,
// }
// Process_Attributes_OS_Specific :: struct{}
// Process_Error :: enum {
// None,
// }
// Signal :: #type proc()
// Kill: Signal = nil
// Interrupt: Signal = nil
// process_start :: proc(name: string, argv: []string, attr: ^Process_Attributes) -> (^Process, Process_Error) {
// return nil, .None
// }
// process_release :: proc(p: ^Process) -> Process_Error {
// return .None
// }
// process_kill :: proc(p: ^Process) -> Process_Error {
// return .None
// }
// process_signal :: proc(p: ^Process, sig: Signal) -> Process_Error {
// return .None
// }
/*
Terminate a process.
This procedure terminates a process, specified by it's handle, `process`.
*/
process_kill :: proc(process: Process) -> (Error) {
return _process_kill(process)
}
+9 -2
View File
@@ -577,6 +577,13 @@ _process_close :: proc(process: Process) -> (Error) {
return nil
}
_process_kill :: proc(process: Process) -> (Error) {
if !windows.TerminateProcess(windows.HANDLE(process.handle), 9) {
return _get_platform_error()
}
return nil
}
@(private)
_filetime_to_duration :: proc(filetime: windows.FILETIME) -> time.Duration {
ticks := u64(filetime.dwHighDateTime)<<32 | u64(filetime.dwLowDateTime)
@@ -695,8 +702,8 @@ _parse_command_line :: proc(cmd_line_w: [^]u16, allocator: runtime.Allocator) ->
for arg_w, i in argv_w[:argc] {
arg, arg_err := windows.wstring_to_utf8(arg_w, -1, allocator)
if arg_err != nil {
for arg in argv[:i] {
delete(arg, allocator)
for s in argv[:i] {
delete(s, allocator)
}
delete(argv, allocator)
return nil, arg_err