diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-07-17 14:55:15 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-07-17 14:55:15 +0200 |
commit | c5ff2059f619ac91c14d55412314d1c67de6a593 (patch) | |
tree | 18c324c5d2bbbe9a913ae693ff75b109d050a1e5 /proc.c | |
parent | 5d6d5f85d8ed49698eb3d790308e05a50b784c54 (diff) |
flowtop, netsniff-ng: Move process name extraction to own function
flowtop and the netsniff-ng's netlink message dissector both need to get
the process name for a pid from /proc/<pid>/exe, thus move that
functionality to an own function.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -64,3 +64,18 @@ int set_sched_status(int policy, int priority) return 0; } + +ssize_t proc_get_cmdline(unsigned int pid, char *cmdline, size_t len) +{ + ssize_t ret; + char path[1024]; + + snprintf(path, sizeof(path), "/proc/%u/exe", pid); + ret = readlink(path, cmdline, len - 1); + if (ret < 0) + cmdline[0] = '\0'; + else + cmdline[ret] = '\0'; + + return ret; +} |