mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
[os2/process]: Add process list function
This commit is contained in:
@@ -104,6 +104,13 @@ get_ppid :: proc() -> int {
|
|||||||
return _get_ppid()
|
return _get_ppid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Obtain ID's of all processes running in the system.
|
||||||
|
*/
|
||||||
|
process_list :: proc(allocator: runtime.Allocator) -> ([]int, Error) {
|
||||||
|
return _process_list(allocator)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Process :: struct {
|
Process :: struct {
|
||||||
pid: int,
|
pid: int,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package os2
|
package os2
|
||||||
|
|
||||||
import "core:sys/windows"
|
import "core:sys/windows"
|
||||||
|
import "base:runtime"
|
||||||
|
|
||||||
_exit :: proc "contextless" (code: int) -> ! {
|
_exit :: proc "contextless" (code: int) -> ! {
|
||||||
windows.ExitProcess(u32(code))
|
windows.ExitProcess(u32(code))
|
||||||
@@ -44,3 +45,18 @@ _get_ppid :: proc() -> int {
|
|||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_process_list :: proc(allocator: runtime.Allocator) -> ([]int, Error) {
|
||||||
|
pid_list := make([dynamic]int, allocator)
|
||||||
|
snap := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
|
||||||
|
if snap == windows.INVALID_HANDLE_VALUE {
|
||||||
|
return pid_list[:], _get_platform_error()
|
||||||
|
}
|
||||||
|
entry := windows.PROCESSENTRY32W { dwSize = size_of(windows.PROCESSENTRY32W) }
|
||||||
|
status := windows.Process32FirstW(snap, &entry)
|
||||||
|
for status {
|
||||||
|
append(&pid_list, cast(int) entry.th32ProcessID)
|
||||||
|
status = windows.Process32NextW(snap, &entry)
|
||||||
|
}
|
||||||
|
return pid_list[:], nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user