Skip to content

Instantly share code, notes, and snippets.

@ketotek
ketotek / libproc_example.swift
Created May 31, 2019 14:51 — forked from kainjow/libproc_example.swift
Swift example of C libproc API
import Darwin
// Call proc_listallpids once with nil/0 args to get the current number of pids
let initialNumPids = proc_listallpids(nil, 0)
// Allocate a buffer of these number of pids.
// Make sure to deallocate it as this class does not manage memory for us.
let buffer = UnsafeMutablePointer<pid_t>.allocate(capacity: Int(initialNumPids))
defer {
buffer.deallocate()