NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |EXAMPLE |FILES |SEE ALSO |AUTHOR |REPORTING BUGS |LICENSE |RESOURCES |NOTES |COLOPHON | |
LIBTRACEEVENT(3) libtraceevent ManualLIBTRACEEVENT(3)tep_register_comm, tep_override_comm, tep_is_pid_registered, tep_data_comm_from_pid, tep_data_pid_from_comm, tep_cmdline_pid - Manage pid to process name mappings.
#include <event-parse.h> inttep_register_comm(struct tep_handle *tep, const char *comm, intpid); inttep_override_comm(struct tep_handle *tep, const char *comm, intpid); booltep_is_pid_registered(struct tep_handle *tep, intpid); const char *tep_data_comm_from_pid(struct tep_handle *pevent, intpid); struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm, struct cmdline *next); inttep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
These functions can be used to handle the mapping between pid and process name. The library builds a cache of these mappings, which is used to display the name of the process, instead of its pid. This information can be retrieved from tracefs/saved_cmdlines file. Thetep_register_comm()function registers apid / process name mapping. If a command with the samepid is already registered, an error is returned. Thepid argument is the process ID, thecomm argument is the process name,tep is the event context. Thecomm is duplicated internally. Thetep_override_comm()function registers apid / process name mapping. If a process with the same pid is already registered, the process name string is udapted with the new one. Thepid argument is the process ID, thecomm argument is the process name,tep is the event context. Thecomm is duplicated internally. Thetep_is_pid_registered()function checks if a pid has a process name mapping registered. Thepid argument is the process ID,tep is the event context. Thetep_data_comm_from_pid()function returns the process name for a given pid. Thepid argument is the process ID,tep is the event context. The returned string should not be freed, but will be freed when thetep handler is closed. Thetep_data_pid_from_comm()function returns a pid for a given process name. Thecomm argument is the process name,tep is the event context. The argumentnext is the cmdline structure to search for the next pid. As there may be more than one pid for a given process, the result of this call can be passed back into a recurring call in thenext parameter, to search for the next pid. Ifnext is NULL, it will return the first pid associated with thecomm. The function performs a linear search, so it may be slow. Thetep_cmdline_pid()function returns the pid associated with a givencmdline. Thetep argument is the event context.
tep_register_comm()function returns 0 on success. In case of an error -1 is returned and errno is set to indicate the cause of the problem: ENOMEM, if there is not enough memory to duplicate thecomm or EEXIST if a mapping for thispid is already registered.tep_override_comm()function returns 0 on success. In case of an error -1 is returned and errno is set to indicate the cause of the problem: ENOMEM, if there is not enough memory to duplicate thecomm.tep_is_pid_registered()function returns true if thepid has a process name mapped to it, false otherwise.tep_data_comm_from_pid()function returns the process name as string, or the string "<...>" if there is no mapping for the given pid.tep_data_pid_from_comm()function returns a pointer to a struct cmdline, that holds a pid for a given process, or NULL if none is found. This result can be passed back into a recurring call as thenext parameter of the function.tep_cmdline_pid()functions returns the pid for the give cmdline. Ifcmdline is NULL, then -1 is returned.
The following example registers pid for command "ls", in context of eventtep and performs various searches for pid / process name mappings: #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); }event-parse.h Header file to include in order to have access to the library APIs.-ltraceevent Linker switch to add when building a program that uses the library.
libtraceevent(3),trace-cmd(1)
Steven Rostedt<rostedt@goodmis.org[1]>, author oflibtraceevent.Tzvetomir Stoyanov<tz.stoyanov@gmail.com[2]>, author of this man page.
Report bugs to <linux-trace-devel@vger.kernel.org[3]>
libtraceevent is Free Software licensed under the GNU LGPL 2.1
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
1. rostedt@goodmis.org mailto:rostedt@goodmis.org 2. tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com 3. linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org
This page is part of thelibtraceevent (Linux kernel trace event library) project. Information about the project can be found at ⟨https://www.trace-cmd.org/⟩. If you have a bug report for this manual page, see ⟨https://www.trace-cmd.org/⟩. This page was obtained from the project's upstream Git repository ⟨https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git⟩ on 2025-08-11. (At that time, the date of the most recent commit that was found in the repository was 2025-05-30.) If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up-to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orglibtraceevent 1.7.3 09/24/2023LIBTRACEEVENT(3)Pages that refer to this page:tep_parse_saved_cmdlines(3)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |