init(forPID:)

Gets the task port for a process.

TaskForPID.swift:17Task For PID.md
convenience init(forPID pid: pid_t) throws

When this function is used on the base class, it will attempt to get and return a control port. When it is used on a flavored subclass, it will attempt to get a port of that flavor and return it.

// base class
let port1 = try Mach.Task(forPID: somePid) // gets a task control port
// flavored subclasses
let port2 = try Mach.TaskControl(forPID: somePid) // gets a task control port
let port3 = try Mach.TaskRead(forPID: somePid) // gets a task read port
let port4 = try Mach.TaskInspect(forPID: somePid) // gets a task inspect port
let port5 = try Mach.TaskName(forPID: somePid) // gets a task name port