oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package fprobe
2
3import (
4 "os"
5
6 "golang.org/x/sys/unix"
7)
8
9// ProcArgs is pid's KERN_PROCARGS2: its argument count, executable path,
10// arguments and environment, as the kernel keeps them.
11func ProcArgs(pid int) ([]byte, error) { return unix.SysctlRaw("kern.procargs2", pid) }
12
13// ownPIDs is every process of this user (KERN_PROC_UID).
14func ownPIDs() ([]int, error) {
15 procs, err := unix.SysctlKinfoProcSlice("kern.proc.uid", os.Getuid())
16 if err != nil {
17 return nil, err
18 }
19 out := make([]int, 0, len(procs))
20 for _, p := range procs {
21 out = append(out, int(p.Proc.P_pid))
22 }
23 return out, nil
24}
25