LIBTRACEEVENT(3)
π LIBTRACEEVENT(3) β the libtraceevent manual, bestie edition π
okay so this is a page straight outta the libtraceevent manual, and it's all about the pid β process name situation. strap in π
β¨ NAME β¨
tep_register_comm, tep_override_comm, tep_is_pid_registered, tep_data_comm_from_pid, tep_data_pid_from_comm, tep_cmdline_pid β managing pid-to-process-name mappings, basically the group chat between "who is this number" and "oh that's their name" π
πΈ SYNOPSIS πΈ
#include <event-parse.h>
int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
bool tep_is_pid_registered(struct tep_handle *tep, int pid);
const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid);
struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm, struct cmdline *next);
int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
π¦ DESCRIPTION π¦
so these functions handle the whole mapping between a pid and a process name. the library builds a lil cache of these mappings, and that cache is what lets it show you the name of a process instead of just a sad lonely pid. you can pull this info out of the tracefs/saved_cmdlines file β¨
tep_register_comm()β registers a pid / process name mapping. if a command with the same pid is already registered, it returns an error, no cap. thepidargument is the process ID, thecommargument is the process name, andtepis the event context. thecommgets duplicated internally πtep_override_comm()β also registers a pid / process name mapping, but if a process with the same pid is already in there, the process name string gets updated with the new one (iconic, no drama). thepidargument is the process ID, thecommargument is the process name,tepis the event context. thecommis duplicated internally πtep_is_pid_registered()β checks whether a pid already has a process name mapping registered.pidis the process ID,tepis the event context. yes/no energy only πtep_data_comm_from_pid()β returns the process name for a given pid.pidis the process ID,tepis the event context. the returned string should not be freed by you β it gets freed when the tep handler is closed, so hands off bestie πtep_data_pid_from_comm()β returns a pid for a given process name.commis the process name,tepis the event context. thenextargument is the cmdline structure to search for the next pid. because there can be more than one pid for a given process, you can pass the result of this call right back in through thenextparameter on a recurring call to hunt down the next pid. ifnextisNULL, it returns the first pid associated with the comm. > heads up: this function does a linear search, so it may be slow πtep_cmdline_pid()β returns the pid associated with a given cmdline. thetepargument is the event context π«Ά
β RETURN VALUE β
tep_register_comm()β returns0on success. on error,-1comes back anderrnois set to tell you why:ENOMEMif there isn't enough memory to duplicate the comm, orEEXISTif a mapping for this pid is already registered πtep_override_comm()β returns0on success. on error,-1anderrnoexplains it:ENOMEMif there's not enough memory to duplicate the comm β¨tep_is_pid_registered()β returnstrueif the pid has a process name mapped to it,falseotherwise πtep_data_comm_from_pid()β returns the process name as a string, or the string"<...>"if there's no mapping for that pid πtep_data_pid_from_comm()β returns a pointer to astruct cmdlinethat holds a pid for a given process, orNULLif none is found. you can pass this result back into a recurring call as thenextparameter π¦tep_cmdline_pid()β returns the pid for the given cmdline. ifcmdlineisNULL, then-1is returned π
π₯ EXAMPLE π₯
this example registers a pid for the command "ls", in the context of the event tep, and then does a bunch of different searches for pid / process name mappings. slay:
#include <event-parse.h>
...
int ret;
int ls_pid = 1021;
struct tep_handle *tep = tep_alloc();
...
ret = tep_register_comm(tep, "ls", ls_pid);
if (ret != 0 && errno == EEXIST)
ret = tep_override_comm(tep, "ls", ls_pid);
if (ret != 0) {
/* Failed to register pid / command mapping */
}
...
if (tep_is_pid_registered(tep, ls_pid) == 0) {
/* Command mapping for ls_pid is not registered */
}
...
const char *comm = tep_data_comm_from_pid(tep, ls_pid);
if (comm) {
/* Found process name for ls_pid */
}
...
int pid;
struct cmdline *cmd = tep_data_pid_from_comm(tep, "ls", NULL);
while (cmd) {
pid = tep_cmdline_pid(tep, cmd);
/* Found pid for process "ls" */
cmd = tep_data_pid_from_comm(tep, "ls", cmd);
}
π FILES π
event-parse.h- header file you gotta include to get access to the library APIs π«Ά
-ltraceevent- the linker switch you add when building a program that uses the library β¨
π SEE ALSO π
π AUTHOR π
- Steven Rostedt <rostedt@goodmis.org>, author of libtraceevent π
- Tzvetomir Stoyanov <tz.stoyanov@gmail.com>, author of this man page π
π REPORTING BUGS π
Report bugs to <linux-trace-devel@vger.kernel.org> β they wanna hear it, fr fr π
π§ LICENSE π§
libtraceevent is Free Software licensed under the GNU LGPL 2.1 πβ¨
πΈ RESOURCES πΈ
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
π NOTES π
rostedt@goodmis.orgmailto:rostedt@goodmis.orgtz.stoyanov@gmail.commailto:tz.stoyanov@gmail.comlinux-trace-devel@vger.kernel.orgmailto:linux-trace-devel@vger.kernel.org
and that's the whole page bestie, periodt π this was libtraceevent 1.9.0, dated 06/15/2026 β thanks for reading, ily, go map some pids ππ¦β¨
π¦ where this page comes from
- ubuntu stonking: libtraceevent-doc 1:1.9.0-2 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms