Quantcast
Viewing latest article 2
Browse Latest Browse All 3

Answer by nneonneo for Getting the full path of a running PID with C/C++ without using the system function (Linux)

Use readlink("/proc/<pid>/exe", buf, bufsize) to get the path to <pid>'s executable. This works on Linux, provided procfs is available (it usually is).

Example usage:

int get_exe_for_pid(pid_t pid, char *buf, size_t bufsize) {    char path[32];    sprintf(path, "/proc/%d/exe", pid);    return readlink(path, buf, bufsize);}

Returns -1 on failure and sets errno.


Viewing latest article 2
Browse Latest Browse All 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>