PMC_ATTACH(3)
π PMC_ATTACH(3) β bestie edition π
ok so this one is pmc_attach and pmc_detach, straight out of the Performance Counters Library (libpmc, link it with -lpmc), and it's the manual page for the PMC_ATTACH(3) family of functions. it's giving "let me introduce my little counters to your processes" energy and honestly? iconic. π
β¨ SYNOPSIS β¨
#include <pmc.h>
int
pmc_attach(pmc_id_t pmcid, pid_t pid);
int
pmc_detach(pmc_id_t pmcid, pid_t pid);
that's the whole vibe. two functions, two ints, one header. slay. π
πΈ DESCRIPTION πΈ
okay so these two functions are literally the bouncers for the set of target processes that a process scope PMC keeps track of. like, who's allowed in the club, who's getting kicked out. π«Ά
Function pmc_attach() attaches a process scope PMC β the one you name with argument pmcid β to a target process β the one you name with argument pid. and here's a cute little detail: pid can be zero, and zero means "the current process," i.e. you. self-love, periodt. π
if the PMC was allocated with the modifier PMC_F_DESCENDANTS, then it will additionally attach to the current and future descendents of the target process you specified. the whole family tree gets tracked, no cap. π
real talk though: the PMC should be in a quiescent state β meaning not running. don't try to attach a live one, it will not go well for you, bestie. π
Function pmc_detach() does the opposite: it detaches a process scope PMC specified by argument pmcid from a process specified by argument pid. and again, pid may be zero to denote the current process. bye bestie, you're uninvited. π
β RETURN VALUES β
upon successful completion, the value 0 is returned. and when it's not a slay? the value -1 is returned and the global variable errno gets set to indicate the error. so check your errno, it's literally telling you what went wrong. π¦
π₯ ERRORS π₯
π a call to pmc_attach() may fail with these:
[EBUSY]β argumentpmcidspecified a PMC that was not in a quiescent state. it's busy, it's booked, it's not taking visitors rn. π[EBUSY]β the target process specified by functionpmc_attachis already being tracked by another process scope PMC that uses the same PMC hardware resources. two PMCs fighting over the same hardware, not the vibe check we wanted.[EEXIST]β the target process is already being tracked by the specified PMC. bestie it's already in the group chat, stop re-adding it. π[EINVAL]β argumentpmcidspecified a PMC with system scope. wrong scope, wrong party. β¨[EINVAL]β argumentpidspecified an illegal process id. that's not a real pid, girl.[EINVAL]β the current process does not own a PMC with the handle specified in argumentpmcid. not yours, don't touch. π[EPERM]β the caller lacked the privilege needed to attach PMCs to the specified target process. permissions said no. π[EPERM]β (i386 and amd64 architectures) the PMC specified by argumentpmcidhas been setup to allow the use of theRDPMCinstruction for self measurement. yeah, that setup doesn't allow this. nope. π[ESRCH]β the current process does not own any PMCs. zero PMCs, zero chill.[ESRCH]β the process specified by argumentpiddid not exist. ghost process. it's giving nothing because it's not there. π»
π¦ a call to pmc_detach() may fail with these:
[EINVAL]β argumentpmcidspecified a PMC with system scope. again. wrong scope. periodt. β¨[EINVAL]β argumentpidspecified an illegal process id. same energy, still illegal.[EINVAL]β the current process does not own a PMC with the handle specified in argumentpmcid. not your PMC, not your problem, but also:EINVAL. π[EINVAL]β the specified PMC was not attached to the target process. you can't detach what was never attached, bestie, that's not how this works. π[ESRCH]β the current process does not own any PMCs. empty hands, empty PMC list.[ESRCH]β the process specified by argumentpidis not being monitored byhwpmc(4). nobody's watching that one.[ESRCH]β the process specified by argumentpiddid not exist. still a ghost. stillESRCH. π»
π SEE ALSO π
go read them, iykyk. πβ¨
and that's the whole page, bestie!! π this little masterpiece came from Debian, dated November 25, 2007 β vintage but still absolutely serving. mwah, go attach some PMCs responsibly π«Άπ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2007 Joseph Koshy. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms