osx - How do I get the full path for a process on OS X? -



osx - How do I get the full path for a process on OS X? -

i know can pid process using ps, how find total path of process?

os x has libproc library, can used gather different process informations. in order find absolute path given pid, next code can used:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <libproc.h> int main (int argc, char* argv[]) { pid_t pid; int ret; char pathbuf[proc_pidpathinfo_maxsize]; if ( argc > 1 ) { pid = (pid_t) atoi(argv[1]); ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf)); if ( ret <= 0 ) { fprintf(stderr, "pid %d: proc_pidpath ();\n", pid); fprintf(stderr, " %s\n", strerror(errno)); } else { printf("proc %d: %s\n", pid, pathbuf); } } homecoming 0; }

example compile , run (above code stored in pathfind.c, 32291 pid of process i'm trying find path info for):

$ cc pathfind.c -o pathfind $ ./pathfind 32291 proc 32291: /some/path/your-binary-app

refer blog post: http://astojanov.wordpress.com/2011/11/16/mac-os-x-resolve-absolute-path-using-process-pid/

osx process path pid ps

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -