How can I get the process name in C? The same name, which is in /proc/$pid/status. I do not want to parse that file. Is there any programmatic way of doing this
/proc/$pid/status
This is a version that works on macOS, FreeBSD and Linux.
#if defined(__APPLE__) || defined(__FreeBSD__) const char * appname = getprogname(); #elif defined(_GNU_SOURCE) const char * appname = program_invocation_name; #else const char * appname = "?"; #endif